Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SubscriptionCheckoutFormInitialize. #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion iyzipay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
RetrievePaymentDetails,
RetrieveTransactions,
IyziLinkProduct,
IyziFileBase64Encoder)
IyziFileBase64Encoder,
SubscriptionCheckoutFormInitialize)

from iyzipay.pki_builder import ( # noqa
PKIBuilder,
Expand Down
25 changes: 25 additions & 0 deletions iyzipay/iyzipay_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,18 @@ def card_pki(card):
pki_builder.append('cardHolderName', card.get('cardHolderName'))
return pki_builder.get_request_string()

@staticmethod
def customer_pki(buyer):
pki_builder = iyzipay.PKIBuilder('')
pki_builder.append('name', buyer.get('name'))
pki_builder.append('surname', buyer.get('surname'))
pki_builder.append('identityNumber', buyer.get('identityNumber'))
pki_builder.append('email', buyer.get('email'))
pki_builder.append('gsmNumber', buyer.get('gsmNumber'))
pki_builder.append('billingAddress',
IyzipayResource.address_pki(buyer.get('billingAddress')))
return pki_builder.get_request_string()


class ApiTest(IyzipayResource):
def retrieve(self, options):
Expand Down Expand Up @@ -879,3 +891,16 @@ def delete(self, request, options):
raise Exception('token must be in request')
token = str(request.get('token'))
return self.connect('DELETE', '/v2/iyzilink/products/' + token, options)

class SubscriptionCheckoutFormInitialize(IyzipayResource):
def create(self, request, options):
pki = self.to_pki_string(request)
return self.connect('POST', '/v2/subscription/checkoutform/initialize', options, request, pki)

def to_pki_string(self, request):
pki_builder = iyzipay.PKIBuilder(self.resource_pki(request))
pki_builder.append('pricingPlanReferenceCode', request.get('pricingPlanReferenceCode'))
pki_builder.append('subscriptionInitialStatus', request.get('subscriptionInitialStatus'))
pki_builder.append('customer', self.customer_pki(request.get('customer')))
pki_builder.append('callbackUrl', request.get('callbackUrl'))
return pki_builder.get_request_string()
36 changes: 36 additions & 0 deletions samples/initialize_subscription_checkout_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import iyzipay

options = {
'api_key': iyzipay.api_key,
'secret_key': iyzipay.secret_key,
'base_url': iyzipay.base_url
}

address = {
'contactName': 'John Doe',
'city': 'Istanbul',
'country': 'Turkey',
'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1'
}

customer = {
'name': 'John',
'surname': 'Doe',
'gsmNumber': '+905350000000',
'email': 'email@email.com',
'identityNumber': '11111111111',
'billingAddress': address
}

request = {
'locale': 'tr',
'conversationId': '123456789',
'callbackUrl': 'https://www.merchant.com/callback',
'pricingPlanReferenceCode': '123456',
'subscriptionInitialStatus': 'ACTIVE',
'customer': customer
}

checkout_form_initialize = iyzipay.SubscriptionCheckoutFormInitialize().create(request, options)

print(checkout_form_initialize.read().decode('utf-8'))