From 7ea6576d1bef70526fa5667741a27fbb86fdeac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Thu, 19 Mar 2020 10:18:20 +0300 Subject: [PATCH 1/9] add subscription, create get delete getlist update --- iyzipay/__init__.py | 5 +- iyzipay/iyzipay_resource.py | 65 ++++++++++++++----- samples/subscription_create_product.py | 19 ++++++ samples/subscription_delete_product.py | 16 +++++ samples/subscription_retrieve_product.py | 16 +++++ samples/subscription_retrieve_product_list.py | 18 +++++ samples/subscription_update_product.py | 17 +++++ 7 files changed, 139 insertions(+), 17 deletions(-) create mode 100644 samples/subscription_create_product.py create mode 100644 samples/subscription_delete_product.py create mode 100644 samples/subscription_retrieve_product.py create mode 100644 samples/subscription_retrieve_product_list.py create mode 100644 samples/subscription_update_product.py diff --git a/iyzipay/__init__.py b/iyzipay/__init__.py index 819a11f..eb4f5ed 100644 --- a/iyzipay/__init__.py +++ b/iyzipay/__init__.py @@ -5,8 +5,8 @@ # Nurettin Bakkal # Configuration variables -api_key = 'your api key' -secret_key = 'your secret key' +api_key = 'sandbox-FJFGQCzjOiv9KxoI2rAChbXTcpCwnKhn' +secret_key = 'sandbox-3AlqFpeUX4d9Qy49sMokoF1YNPa7g7Gl' base_url = 'sandbox-api.iyzipay.com' # Resource @@ -50,6 +50,7 @@ RetrievePaymentDetails, RetrieveTransactions, IyziLinkProduct, + SubscriptionProduct, IyziFileBase64Encoder) from iyzipay.pki_builder import ( # noqa diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index 556b1f2..a9fe02a 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -11,11 +11,12 @@ import iyzipay + 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.35' } @@ -58,7 +59,7 @@ def get_http_header_v2(self, url, options, random_str, body_str): url = url.split('?')[0] hashed_v2_str = self.generate_v2_hash(options['api_key'], url, options['secret_key'], random_str, body_str) self.header.update( - {'Authorization': 'IYZWSv2 %s' % (hashed_v2_str)}) + {'Authorization': 'IYZWSv2 %s' % (hashed_v2_str)}) return self.header def generate_v2_hash(self, api_key, url, secret_key, random_str, body_str): @@ -68,7 +69,7 @@ def generate_v2_hash(self, api_key, url, secret_key, random_str, body_str): else: msg = (random_str + url + body_str) - hmac_obj = hmac.new(secret_key,digestmod=hashlib.sha256) + hmac_obj = hmac.new(secret_key, digestmod=hashlib.sha256) hmac_obj.update(msg) signature = hmac_obj.hexdigest() authorization_params = [ @@ -87,8 +88,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): @@ -106,7 +107,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): @@ -848,17 +850,21 @@ def to_pki_string(self, request): pki_builder.append_array('installmentDetails', self.installment_details_pki(request.get('installmentDetails'))) return pki_builder.get_request_string() + 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): def retrieve(self, request, options): page = str(request.get('page')) transactionDate = str(request.get('transactionDate')) - query_params = 'transactionDate='+transactionDate+'&page='+page - return self.connect('GET', '/v2/reporting/payment/transactions?'+query_params, options) + query_params = 'transactionDate=' + transactionDate + '&page=' + page + return self.connect('GET', '/v2/reporting/payment/transactions?' + query_params, options) + class IyziFileBase64Encoder: @staticmethod @@ -866,29 +872,58 @@ def encode(file_path): with open(file_path, "rb") as f: return base64.b64encode(f.read()).decode('utf-8') + 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') token = str(request.get('token')) - return self.connect('GET', '/v2/iyzilink/products/'+ token, options) + return self.connect('GET', '/v2/iyzilink/products/' + token, options) def get(self, request, options): page = str(request.get('page') or 1) count = str(request.get('count') or 10) - return self.connect('GET', '/v2/iyzilink/products/?page='+page+'&count='+count, options) + return self.connect('GET', '/v2/iyzilink/products/?page=' + page + '&count=' + count, options) def update(self, request, options): if request.get('token') is None: raise Exception('token must be in request') token = str(request.get('token')) - return self.connect('PUT', '/v2/iyzilink/products/'+ token, options, request) - + 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) + 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('referenceCode') is None: + raise Exception('productReferenceCode must be in request') + product_reference_code = str(request.get('referenceCode')) + return self.connect('PUT', '/v2/subscription/products/' + product_reference_code, 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) diff --git a/samples/subscription_create_product.py b/samples/subscription_create_product.py new file mode 100644 index 0000000..61a8b6b --- /dev/null +++ b/samples/subscription_create_product.py @@ -0,0 +1,19 @@ +# 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': 1234, + 'name': 'Standart', + 'Description': 'Standart Test Product Description' +} + +report = iyzipay.SubscriptionProduct().create(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_delete_product.py b/samples/subscription_delete_product.py new file mode 100644 index 0000000..c89d904 --- /dev/null +++ b/samples/subscription_delete_product.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'referenceCode': "8df0a549-ab22-43ce-a31d-0c38be9723b0", +} + +report = iyzipay.SubscriptionProduct().delete(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_retrieve_product.py b/samples/subscription_retrieve_product.py new file mode 100644 index 0000000..0e63aa5 --- /dev/null +++ b/samples/subscription_retrieve_product.py @@ -0,0 +1,16 @@ +# coding=utf-8 + +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'referenceCode': "8df0a549-ab22-43ce-a31d-0c38be9723b0", +} + +report = iyzipay.SubscriptionProduct().retrieve(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_retrieve_product_list.py b/samples/subscription_retrieve_product_list.py new file mode 100644 index 0000000..03e7961 --- /dev/null +++ b/samples/subscription_retrieve_product_list.py @@ -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', + 'page': 1, + 'count': 1 +} + +report = iyzipay.SubscriptionProduct().get(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_update_product.py b/samples/subscription_update_product.py new file mode 100644 index 0000000..60ed155 --- /dev/null +++ b/samples/subscription_update_product.py @@ -0,0 +1,17 @@ +# coding=utf-8 + +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'name': 'Standart Update', + 'referenceCode': "8df0a549-ab22-43ce-a31d-0c38be9723b0", +} + +report = iyzipay.SubscriptionProduct().update(request, options) +print(report.read().decode('utf-8')) From 9e52cde3df086ecfcbeedc19e3746b7f595700aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Thu, 19 Mar 2020 15:12:10 +0300 Subject: [PATCH 2/9] subscription plan create,get,delete,update,retrieve --- iyzipay/__init__.py | 1 + iyzipay/iyzipay_resource.py | 43 +++++++++++++++++++-- samples/subscription_plans_create.py | 26 +++++++++++++ samples/subscription_plans_delete_plan.py | 17 ++++++++ samples/subscription_plans_get_list.py | 17 ++++++++ samples/subscription_plans_retrieve_plan.py | 17 ++++++++ samples/subscription_plans_update.py | 18 +++++++++ 7 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 samples/subscription_plans_create.py create mode 100644 samples/subscription_plans_delete_plan.py create mode 100644 samples/subscription_plans_get_list.py create mode 100644 samples/subscription_plans_retrieve_plan.py create mode 100644 samples/subscription_plans_update.py diff --git a/iyzipay/__init__.py b/iyzipay/__init__.py index eb4f5ed..11a4a9f 100644 --- a/iyzipay/__init__.py +++ b/iyzipay/__init__.py @@ -51,6 +51,7 @@ RetrieveTransactions, IyziLinkProduct, SubscriptionProduct, + SubscriptionPlan, IyziFileBase64Encoder) from iyzipay.pki_builder import ( # noqa diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index a9fe02a..2c0469f 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -917,13 +917,50 @@ def get(self, request, options): return self.connect('GET', '/v2/subscription/products/?page=' + page + '&count=' + count, options) def update(self, request, options): - if request.get('referenceCode') is None: + if request.get('pricingPlanReferenceCode') is None: raise Exception('productReferenceCode must be in request') - product_reference_code = str(request.get('referenceCode')) - return self.connect('PUT', '/v2/subscription/products/' + product_reference_code, options, 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) diff --git a/samples/subscription_plans_create.py b/samples/subscription_plans_create.py new file mode 100644 index 0000000..f75b8f9 --- /dev/null +++ b/samples/subscription_plans_create.py @@ -0,0 +1,26 @@ +# 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': 1234, + 'name': 'Premium Monthly', + 'price': 500, + 'currencyCode': 'USD', + 'paymentInterval': 'MONTHLY', + 'paymentIntervalCount': 1, + 'trialPeriodDays': 30, + 'planPaymentType': 'RECURRING', + 'recurrenceCount': 12, + 'referenceCode': '6b4803fb-c4f0-4f37-9df7-899a186e1451' +} + +report = iyzipay.SubscriptionPlan().create(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_plans_delete_plan.py b/samples/subscription_plans_delete_plan.py new file mode 100644 index 0000000..d0763a1 --- /dev/null +++ b/samples/subscription_plans_delete_plan.py @@ -0,0 +1,17 @@ +# coding=utf-8 + +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'locale': 'tr', + 'referenceCode': 'b6e6b124-f7bf-452e-b902-1fb3075fae65' +} + +report = iyzipay.SubscriptionPlan().delete(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_plans_get_list.py b/samples/subscription_plans_get_list.py new file mode 100644 index 0000000..df63d86 --- /dev/null +++ b/samples/subscription_plans_get_list.py @@ -0,0 +1,17 @@ +# coding=utf-8 + +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'locale': 'tr', + 'referenceCode': '6b4803fb-c4f0-4f37-9df7-899a186e1451' +} + +report = iyzipay.SubscriptionPlan().get(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_plans_retrieve_plan.py b/samples/subscription_plans_retrieve_plan.py new file mode 100644 index 0000000..6993e22 --- /dev/null +++ b/samples/subscription_plans_retrieve_plan.py @@ -0,0 +1,17 @@ +# coding=utf-8 + +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'locale': 'tr', + 'referenceCode': 'b6e6b124-f7bf-452e-b902-1fb3075fae65' +} + +report = iyzipay.SubscriptionPlan().retrieve(request, options) +print(report.read().decode('utf-8')) diff --git a/samples/subscription_plans_update.py b/samples/subscription_plans_update.py new file mode 100644 index 0000000..39860fb --- /dev/null +++ b/samples/subscription_plans_update.py @@ -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', + 'name': 'Premium Monthly', + 'referenceCode': 'b6e6b124-f7bf-452e-b902-1fb3075fae65' +} + +report = iyzipay.SubscriptionPlan().update(request, options) +print(report.read().decode('utf-8')) From 20008013f3563a78c96920135b8709830ca658e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Sat, 21 Mar 2020 12:56:55 +0300 Subject: [PATCH 3/9] change file names --- ...scription_create_product.py => subscription_product_create.py} | 0 ...scription_delete_product.py => subscription_product_delete.py} | 0 ...ieve_product_list.py => subscription_product_list_retrieve.py} | 0 ...ption_retrieve_product.py => subscription_product_retrieve.py} | 0 ...scription_update_product.py => subscription_product_update.py} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename samples/{subscription_create_product.py => subscription_product_create.py} (100%) rename samples/{subscription_delete_product.py => subscription_product_delete.py} (100%) rename samples/{subscription_retrieve_product_list.py => subscription_product_list_retrieve.py} (100%) rename samples/{subscription_retrieve_product.py => subscription_product_retrieve.py} (100%) rename samples/{subscription_update_product.py => subscription_product_update.py} (100%) diff --git a/samples/subscription_create_product.py b/samples/subscription_product_create.py similarity index 100% rename from samples/subscription_create_product.py rename to samples/subscription_product_create.py diff --git a/samples/subscription_delete_product.py b/samples/subscription_product_delete.py similarity index 100% rename from samples/subscription_delete_product.py rename to samples/subscription_product_delete.py diff --git a/samples/subscription_retrieve_product_list.py b/samples/subscription_product_list_retrieve.py similarity index 100% rename from samples/subscription_retrieve_product_list.py rename to samples/subscription_product_list_retrieve.py diff --git a/samples/subscription_retrieve_product.py b/samples/subscription_product_retrieve.py similarity index 100% rename from samples/subscription_retrieve_product.py rename to samples/subscription_product_retrieve.py diff --git a/samples/subscription_update_product.py b/samples/subscription_product_update.py similarity index 100% rename from samples/subscription_update_product.py rename to samples/subscription_product_update.py From 7a042666754923158458ccba8a581c2445979660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Sat, 21 Mar 2020 15:20:20 +0300 Subject: [PATCH 4/9] add subscription customer --- iyzipay/__init__.py | 2 +- iyzipay/iyzipay_resource.py | 31 ++++++++++++++++++ samples/subscription_customer_create.py | 37 ++++++++++++++++++++++ samples/subscription_customer_get.py | 18 +++++++++++ samples/subscription_customer_retrieve.py | 18 +++++++++++ samples/subscription_customer_update.py | 38 +++++++++++++++++++++++ samples/subscription_plans_get_list.py | 4 ++- 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 samples/subscription_customer_create.py create mode 100644 samples/subscription_customer_get.py create mode 100644 samples/subscription_customer_retrieve.py create mode 100644 samples/subscription_customer_update.py diff --git a/iyzipay/__init__.py b/iyzipay/__init__.py index 11a4a9f..48913f7 100644 --- a/iyzipay/__init__.py +++ b/iyzipay/__init__.py @@ -52,8 +52,8 @@ IyziLinkProduct, SubscriptionProduct, SubscriptionPlan, + SubscriptionCustomer, IyziFileBase64Encoder) from iyzipay.pki_builder import ( # noqa PKIBuilder) - diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index 2c0469f..71f07fd 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -964,3 +964,34 @@ def delete(self, request, options): 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('referenceCode') is None: + raise Exception('referenceCode must be in request') + referenceCode = str(request.get('referenceCode')) + return self.connect('DELETE', '/v2/subscription/customers/' + referenceCode, options) diff --git a/samples/subscription_customer_create.py b/samples/subscription_customer_create.py new file mode 100644 index 0000000..c1d22a7 --- /dev/null +++ b/samples/subscription_customer_create.py @@ -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': 'test@bmsumer.com', + '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')) diff --git a/samples/subscription_customer_get.py b/samples/subscription_customer_get.py new file mode 100644 index 0000000..16efd73 --- /dev/null +++ b/samples/subscription_customer_get.py @@ -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')) diff --git a/samples/subscription_customer_retrieve.py b/samples/subscription_customer_retrieve.py new file mode 100644 index 0000000..6779a26 --- /dev/null +++ b/samples/subscription_customer_retrieve.py @@ -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')) diff --git a/samples/subscription_customer_update.py b/samples/subscription_customer_update.py new file mode 100644 index 0000000..470be1a --- /dev/null +++ b/samples/subscription_customer_update.py @@ -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': 'test@bmsumer.com', + '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')) diff --git a/samples/subscription_plans_get_list.py b/samples/subscription_plans_get_list.py index df63d86..fb61389 100644 --- a/samples/subscription_plans_get_list.py +++ b/samples/subscription_plans_get_list.py @@ -10,7 +10,9 @@ request = { 'locale': 'tr', - 'referenceCode': '6b4803fb-c4f0-4f37-9df7-899a186e1451' + 'referenceCode': '6b4803fb-c4f0-4f37-9df7-899a186e1451', + 'page': 1, + 'count': 1 } report = iyzipay.SubscriptionPlan().get(request, options) From e2f341503613af3c188af3368a4cf94ff1608463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Sat, 21 Mar 2020 16:35:56 +0300 Subject: [PATCH 5/9] start to develop checkout form --- iyzipay/__init__.py | 2 ++ iyzipay/iyzipay_resource.py | 27 +++++++++++--- samples/subscription_checkout_form_check.py | 36 +++++++++++++++++++ .../subscription_checkout_form_initialize.py | 36 +++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 samples/subscription_checkout_form_check.py create mode 100644 samples/subscription_checkout_form_initialize.py diff --git a/iyzipay/__init__.py b/iyzipay/__init__.py index 48913f7..069fb3d 100644 --- a/iyzipay/__init__.py +++ b/iyzipay/__init__.py @@ -53,6 +53,8 @@ SubscriptionProduct, SubscriptionPlan, SubscriptionCustomer, + SubscriptionCheckoutForm, + SubscriptionCheckoutDirect, IyziFileBase64Encoder) from iyzipay.pki_builder import ( # noqa diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index 71f07fd..892cd18 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -991,7 +991,26 @@ def update(self, request, options): return self.connect('PUT', '/v2/subscription/customers/' + customerReferenceCode, 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/customers/' + referenceCode, 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) diff --git a/samples/subscription_checkout_form_check.py b/samples/subscription_checkout_form_check.py new file mode 100644 index 0000000..441459c --- /dev/null +++ b/samples/subscription_checkout_form_check.py @@ -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': 'test@iyzipay.com', + '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')) diff --git a/samples/subscription_checkout_form_initialize.py b/samples/subscription_checkout_form_initialize.py new file mode 100644 index 0000000..484c6b7 --- /dev/null +++ b/samples/subscription_checkout_form_initialize.py @@ -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': 'test@iyzipay.com', + 'gsmNumber': '+905555555555', + 'identityNumber': '00000000000', + 'subscriptionInitialStatus': 'ACTIVE', + "callbackUrl": "https://www.merchant.com/callback", + 'shippingAddress': address, + 'billingAddress': address, +} + +checkout_form_initialize = iyzipay.SubscriptionCheckoutForm().create(request, options) + +print(checkout_form_initialize.read().decode('utf-8')) From 17f3984c7dd58cb3d58320b46ad5a34c4c7b7224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Fri, 12 Jun 2020 14:25:55 +0300 Subject: [PATCH 6/9] change subscription form checkout --- .../subscription_checkout_form_initialize.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/samples/subscription_checkout_form_initialize.py b/samples/subscription_checkout_form_initialize.py index 484c6b7..321a7b1 100644 --- a/samples/subscription_checkout_form_initialize.py +++ b/samples/subscription_checkout_form_initialize.py @@ -20,15 +20,18 @@ 'locale': 'tr', 'conversationId': '123456789', 'pricingPlanReferenceCode': 'b6e6b124-f7bf-452e-b902-1fb3075fae65', - 'name': 'Adı', - 'surname': 'Soyadı', - 'email': 'test@iyzipay.com', - 'gsmNumber': '+905555555555', - 'identityNumber': '00000000000', 'subscriptionInitialStatus': 'ACTIVE', "callbackUrl": "https://www.merchant.com/callback", - 'shippingAddress': address, - 'billingAddress': address, + "customer": { + 'name': 'Adı', + 'surname': 'Soyadı', + 'email': 'test@iyzipay.com', + 'gsmNumber': '+905555555555', + 'identityNumber': 11111113333, + 'shippingAddress': address, + 'billingAddress': address, + } + } checkout_form_initialize = iyzipay.SubscriptionCheckoutForm().create(request, options) From 33d72b89cde8ff9f4229b5b16a08ab487404bb4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Fri, 5 Nov 2021 16:08:05 +0300 Subject: [PATCH 7/9] Update __init__.py --- iyzipay/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/iyzipay/__init__.py b/iyzipay/__init__.py index 9254772..ac52557 100644 --- a/iyzipay/__init__.py +++ b/iyzipay/__init__.py @@ -5,8 +5,8 @@ # Nurettin Bakkal # Configuration variables -api_key = 'sandbox-FJFGQCzjOiv9KxoI2rAChbXTcpCwnKhn' -secret_key = 'sandbox-3AlqFpeUX4d9Qy49sMokoF1YNPa7g7Gl' +api_key = '' +secret_key = '' base_url = 'sandbox-api.iyzipay.com' # Resource @@ -59,4 +59,4 @@ from iyzipay.pki_builder import ( # noqa PKIBuilder, -) \ No newline at end of file +) From 74d4fc93bcc5ce621a28f9f7c30c43494faf6905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Fri, 5 Nov 2021 16:08:43 +0300 Subject: [PATCH 8/9] Update __init__.py --- iyzipay/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iyzipay/__init__.py b/iyzipay/__init__.py index ac52557..b405bec 100644 --- a/iyzipay/__init__.py +++ b/iyzipay/__init__.py @@ -5,8 +5,8 @@ # Nurettin Bakkal # Configuration variables -api_key = '' -secret_key = '' +api_key = 'your api key' +secret_key = 'your secret key' base_url = 'sandbox-api.iyzipay.com' # Resource From 1f8fd3a0c5f4b49629059b394bf42604e0795467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=87a=C4=9Fda=C5=9F=20Kurultay=20Kalkan?= Date: Fri, 5 Nov 2021 16:08:49 +0300 Subject: [PATCH 9/9] Create __init__.py