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

Subscription Features #55

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
6 changes: 5 additions & 1 deletion iyzipay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@
RetrievePaymentDetails,
RetrieveTransactions,
IyziLinkProduct,
SubscriptionProduct,
SubscriptionPlan,
SubscriptionCustomer,
SubscriptionCheckoutForm,
SubscriptionCheckoutDirect,
IyziFileBase64Encoder)

from iyzipay.pki_builder import ( # noqa
PKIBuilder,
)

133 changes: 126 additions & 7 deletions iyzipay/iyzipay_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class IyzipayResource:
RANDOM_STRING_SIZE = 8
RE_SEARCH_V2 = r'/v2/'
header = {
"Accept": "application/json",
"Accept": "application/json",
"Content-type": "application/json",
'x-iyzi-client-version': 'iyzipay-python-1.0.38'
}
Expand Down Expand Up @@ -72,8 +72,8 @@ def prepare_auth_string(self, options, random_str, pki_string):

def generate_random_string(self, size):
return "".join(
random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in
range(size))
random.SystemRandom().choice(string.ascii_letters + string.digits) for _ in
range(size))

@staticmethod
def generate_hash(api_key, secret_key, random_string, pki_string):
Expand All @@ -89,7 +89,8 @@ def format_header_string(api_key, hashed):

@staticmethod
def resource_pki(request):
return 'locale=' + request.get('locale') + (',conversationId=' + request.get('conversationId') + ',' if request.get('conversationId') else ',')
return 'locale=' + request.get('locale') + (
',conversationId=' + request.get('conversationId') + ',' if request.get('conversationId') else ',')

@staticmethod
def buyer_pki(buyer):
Expand Down Expand Up @@ -835,7 +836,9 @@ def to_pki_string(self, request):
class RetrievePaymentDetails(IyzipayResource):
def retrieve(self, request, options):
payment_conversation_id = str(request.get('paymentConversationId'))
return self.connect('GET', '/v2/reporting/payment/details?paymentConversationId=' + payment_conversation_id, options)
return self.connect('GET', '/v2/reporting/payment/details?paymentConversationId=' + payment_conversation_id,
options)



class RetrieveTransactions(IyzipayResource):
Expand All @@ -856,7 +859,7 @@ def encode(file_path):
class IyziLinkProduct(IyzipayResource):
def create(self, request, options):
return self.connect('POST', '/v2/iyzilink/products/', options, request)

def retrieve(self, request, options):
if request.get('token') is None:
raise Exception('token must be in request')
Expand All @@ -873,9 +876,125 @@ def update(self, request, options):
raise Exception('token must be in request')
token = str(request.get('token'))
return self.connect('PUT', '/v2/iyzilink/products/' + token, options, request)

def delete(self, request, options):
if request.get('token') is None:
raise Exception('token must be in request')
token = str(request.get('token'))
return self.connect('DELETE', '/v2/iyzilink/products/' + token, options)


class SubscriptionProduct(IyzipayResource):
def create(self, request, options):
return self.connect('POST', '/v2/subscription/products/', options, request)

def retrieve(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode')
referenceCode = str(request.get('referenceCode'))
return self.connect('GET', '/v2/subscription/products/' + referenceCode, options, request)

def get(self, request, options):
page = str(request.get('page') or 1)
count = str(request.get('count') or 10)
return self.connect('GET', '/v2/subscription/products/?page=' + page + '&count=' + count, options)

def update(self, request, options):
if request.get('pricingPlanReferenceCode') is None:
raise Exception('productReferenceCode must be in request')
pricingPlanReferenceCode = str(request.get('pricingPlanReferenceCode'))
return self.connect('PUT', '/v2/subscription/products/' + pricingPlanReferenceCode, options, request)

def delete(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode must be in request')
referenceCode = str(request.get('referenceCode'))
return self.connect('DELETE', '/v2/subscription/products/' + referenceCode, options)


class SubscriptionPlan(IyzipayResource):
def create(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode')
referenceCode = str(request.get('referenceCode'))
return self.connect('POST', '/v2/subscription/products/' + referenceCode + '/' + 'pricing-plans', options,
request)

def retrieve(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode')
referenceCode = str(request.get('referenceCode'))
return self.connect('GET', '/v2/subscription/pricing-plans/' + referenceCode, options, request)

def get(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode')
referenceCode = str(request.get('referenceCode'))
page = str(request.get('page') or 1)
count = str(request.get('count') or 10)
return self.connect('GET',
'/v2/subscription/products/' + referenceCode + '/' + 'pricing-plans?page=' + page + '&count=' + count,
options)

def update(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode must be in request')
referenceCode = str(request.get('referenceCode'))
return self.connect('PUT', '/v2/subscription/pricing-plans/' + referenceCode, options, request)

def delete(self, request, options):
if request.get('referenceCode') is None:
raise Exception('referenceCode must be in request')
referenceCode = str(request.get('referenceCode'))
return self.connect('DELETE', '/v2/subscription/pricing-plans/' + referenceCode, options)


class SubscriptionCustomer(IyzipayResource):
def create(self, request, options):
return self.connect('POST', '/v2/subscription/customers', options,
request)

def retrieve(self, request, options):
if request.get('customerReferenceCode') is None:
raise Exception('customerReferenceCode')
customerReferenceCode = str(request.get('customerReferenceCode'))
return self.connect('GET', '/v2/subscription/customers/' + customerReferenceCode, options, request)

def get(self, request, options):
page = str(request.get('page') or 1)
count = str(request.get('count') or 10)
return self.connect('GET',
'/v2/subscription/customers/?page=' + page + '&count=' + count,
options)

def update(self, request, options):
if request.get('customerReferenceCode') is None:
raise Exception('customerReferenceCode must be in request')
customerReferenceCode = str(request.get('customerReferenceCode'))
return self.connect('PUT', '/v2/subscription/customers/' + customerReferenceCode, options, request)

def delete(self, request, options):
if request.get('customerReferenceCode') is None:
raise Exception('customerReferenceCode must be in request')
customerReferenceCode = str(request.get('customerReferenceCode'))
return self.connect('DELETE', '/v2/subscription/customers/' + customerReferenceCode, options)


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

def get(self, request, options):
if request.get('token') is None:
raise Exception('token must be in request')
return self.connect('POST', '/v2/subscription/checkoutform/', options, request)

class SubscriptionCheckoutDirect(IyzipayResource):
def create(self, request, options):
return self.connect('POST', '/v2/subscription/initialize', options, request)

def get(self, request, options):
if request.get('token') is None:
raise Exception('token must be in request')
return self.connect('POST', '/v2/subscription/checkoutform/', options, request)

36 changes: 36 additions & 0 deletions samples/subscription_checkout_form_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# coding=utf-8

import iyzipay

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

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

request = {
'locale': 'tr',
'conversationId': '123456789',
'pricingPlanReferenceCode': 'b6e6b124-f7bf-452e-b902-1fb3075fae65',
'name': 'Adı',
'surname': 'Soyadı',
'email': '[email protected]',
'gsmNumber': '+905555555555',
'identityNumber': '00000000000',
'subscriptionInitialStatus': 'ACTIVE',
"callbackUrl": "https://www.merchant.com/callback",
'shippingAddress': address,
'billingAddress': address,
}

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

print(checkout_form_initialize.read().decode('utf-8'))
39 changes: 39 additions & 0 deletions samples/subscription_checkout_form_initialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# coding=utf-8

import iyzipay

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

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

request = {
'locale': 'tr',
'conversationId': '123456789',
'pricingPlanReferenceCode': 'b6e6b124-f7bf-452e-b902-1fb3075fae65',
'subscriptionInitialStatus': 'ACTIVE',
"callbackUrl": "https://www.merchant.com/callback",
"customer": {
'name': 'Adı',
'surname': 'Soyadı',
'email': '[email protected]',
'gsmNumber': '+905555555555',
'identityNumber': 11111113333,
'shippingAddress': address,
'billingAddress': address,
}

}

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

print(checkout_form_initialize.read().decode('utf-8'))
37 changes: 37 additions & 0 deletions samples/subscription_customer_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# coding=utf-8

import iyzipay

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

request = {
'locale': 'tr',
'conversationId': '8138',
'name': 'Müşteri Adı',
'surname': 'Müşteri Soyadı',
'email': '[email protected]',
'gsmNumber': '+905445555555',
'identityNumber': '00000000000',
'billingAddress': {
'address': 'Fatura Adres Bilgisi',
'contactName': 'Fatura Adı Soyadı',
'city': 'Fatura Şehri',
'country': 'Fatura Ülkesi',
'zipCode': 'Fatura Posta Kodu',
},
'shippingAddress': {
'contactName': 'Teslimat Adı Soyadı',
'city': 'Teslimat Şehri',
'country': 'Teslimat Ülkesi',
'address': 'Teslimat Adres Bilgisi',
'zipCode': 'Teslimat Posta Kodu',
}

}

report = iyzipay.SubscriptionCustomer().create(request, options)
print(report.read().decode('utf-8'))
18 changes: 18 additions & 0 deletions samples/subscription_customer_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# coding=utf-8

import iyzipay

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

request = {
'page': 1,
'count': 1,

}

report = iyzipay.SubscriptionCustomer().get(request, options)
print(report.read().decode('utf-8'))
18 changes: 18 additions & 0 deletions samples/subscription_customer_retrieve.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# coding=utf-8

import iyzipay

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

request = {
'locale': 'tr',
'conversationId': '8138',
'customerReferenceCode': '2eac778a-1379-4f82-93b1-8bd67ac86c05',
}

report = iyzipay.SubscriptionCustomer().retrieve(request, options)
print(report.read().decode('utf-8'))
38 changes: 38 additions & 0 deletions samples/subscription_customer_update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# coding=utf-8

import iyzipay

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

request = {
'customerReferenceCode': '2eac778a-1379-4f82-93b1-8bd67ac86c05',
'locale': 'tr',
'conversationId': '8138',
'name': 'Müşteri Adı',
'surname': 'Müşteri Soyadı',
'email': '[email protected]',
'gsmNumber': '+905445555555',
'identityNumber': '00000000000',
'billingAddress': {
'address': 'Fatura Adres Bilgisi',
'contactName': 'Fatura Adı Soyadı',
'city': 'Fatura Şehri',
'country': 'Fatura Ülkesi',
'zipCode': 'Fatura Posta Kodu',
},
'shippingAddress': {
'contactName': 'Teslimat Adı Soyadı',
'city': 'Teslimat Şehri',
'country': 'Teslimat Ülkesi',
'address': 'Teslimat Adres Bilgisi',
'zipCode': 'Teslimat Posta Kodu',
}

}

report = iyzipay.SubscriptionCustomer().update(request, options)
print(report.read().decode('utf-8'))
Loading