From 817ec70a549e0f5f695b0977188a36f67ea048b9 Mon Sep 17 00:00:00 2001 From: Osman Keser Date: Wed, 25 Sep 2024 13:41:04 +0300 Subject: [PATCH 1/6] Fix SyntaxWarning error --- iyzipay/pki_builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iyzipay/pki_builder.py b/iyzipay/pki_builder.py index e49b635..93bfa90 100644 --- a/iyzipay/pki_builder.py +++ b/iyzipay/pki_builder.py @@ -8,7 +8,7 @@ def append(self, key, value=None): return self def append_price(self, key, value=None): - if value is not None and value is not "": + if value is not None and value != "": self.append_key_value(key, str(round(float(value), 2))) return self @@ -22,7 +22,7 @@ def append_array(self, key, array=None): return self def append_key_value(self, key, value=None): - if value is not None and value is not "": + if value is not None and value != "": self.request_string = self.request_string + key + "=" + str(value) + "," def remove_trailing_comma(self): From fb5399ea7ac400603595563cecf9ca9d9b38064e Mon Sep 17 00:00:00 2001 From: Osman Keser Date: Wed, 25 Sep 2024 13:41:37 +0300 Subject: [PATCH 2/6] All services switched to Authorization V2 --- iyzipay/iyzipay_resource.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index 7d80414..74eec0d 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -4,15 +4,12 @@ import importlib import json import random -import re import string import iyzipay - class IyzipayResource: RANDOM_STRING_SIZE = 8 - RE_SEARCH_V2 = r'/v2/' header = { "Accept": "application/json", "Content-type": "application/json", @@ -22,6 +19,19 @@ class IyzipayResource: def __init__(self): self.httplib = importlib.import_module('http.client') + def calculate_hmac_sha256_signature(self, params, secret_key): + secret_key = bytes(secret_key.encode('utf-8')) + msg = ':'.join(params).encode('utf-8') + + hmac_obj = hmac.new(secret_key, digestmod=hashlib.sha256) + hmac_obj.update(msg) + return hmac_obj.hexdigest() + + def verify_signature(self, params, secret_key, signature): + calculated_signature = self.calculate_hmac_sha256_signature(params, secret_key) + verified = signature == calculated_signature + print('Signature verified:', verified) + def connect(self, method, url, options, request_body_dict=None, pki=None): connection = self.httplib.HTTPSConnection(options['base_url']) body_str = json.dumps(request_body_dict) @@ -32,15 +42,13 @@ def connect(self, method, url, options, request_body_dict=None, pki=None): def get_http_header(self, url, options=None, body_str=None, pki_string=None): random_str = self.generate_random_string(self.RANDOM_STRING_SIZE) self.header.update({'x-iyzi-rnd': random_str}) - if re.search(self.RE_SEARCH_V2, url, re.IGNORECASE) is not None: - return self.get_http_header_v2(url, options, random_str, body_str) - else: - return self.get_http_header_v1(options, pki_string, random_str) + self.get_http_header_v1(options, pki_string, random_str) + return self.get_http_header_v2(url, options, random_str, body_str) def get_http_header_v1(self, options, pki_string, random_str=None): if pki_string is not None: self.header.update( - {'Authorization': self.prepare_auth_string(options, random_str, pki_string)}) + {'Authorization_Fallback': self.prepare_auth_string(options, random_str, pki_string)}) return self.header def get_http_header_v2(self, url, options, random_str, body_str): From 606cbe6eb717202ae16f535dddd4e7add4bbf29e Mon Sep 17 00:00:00 2001 From: Osman Keser Date: Thu, 26 Sep 2024 16:11:56 +0300 Subject: [PATCH 3/6] signature verification added to existing samples --- iyzipay/iyzipay_resource.py | 4 ++++ samples/create_payment.py | 17 +++++++++++++++-- samples/create_threeds_payment.py | 17 +++++++++++++++-- samples/initialize_bkm.py | 13 +++++++++++-- samples/initialize_checkout_form.py | 13 +++++++++++-- samples/initialize_threeds.py | 13 +++++++++++-- samples/retrieve_bkm_result.py | 21 ++++++++++++++++++--- samples/retrieve_checkout_form_result.py | 19 +++++++++++++++++-- samples/retrieve_payment_result.py | 17 +++++++++++++++-- 9 files changed, 117 insertions(+), 17 deletions(-) diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index 74eec0d..12ade66 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -19,6 +19,10 @@ class IyzipayResource: def __init__(self): self.httplib = importlib.import_module('http.client') + def strip_zero(self, number): + has_zero = number.endswith('.0') + return number.replace('.0', '') if has_zero else number + def calculate_hmac_sha256_signature(self, params, secret_key): secret_key = bytes(secret_key.encode('utf-8')) msg = ':'.join(params).encode('utf-8') diff --git a/samples/create_payment.py b/samples/create_payment.py index 5c41e07..bdf7ad6 100644 --- a/samples/create_payment.py +++ b/samples/create_payment.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -83,6 +84,18 @@ 'basketItems': basket_items } -payment = iyzipay.Payment().create(request, options) +payment = iyzipay.Payment() +payment_result = payment.create(request, options) +payment_result_response = json.load(payment_result) +print('response:', payment_result_response) -print(payment.read().decode('utf-8')) +if payment_result_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = payment_result_response['paymentId'] + currency = payment_result_response['currency'] + basketId = payment_result_response['basketId'] + conversationId = payment_result_response['conversationId'] + paidPrice = payment.strip_zero(str(payment_result_response['paidPrice'])) + price = payment.strip_zero(str(payment_result_response['price'])) + signature = payment_result_response['signature'] + payment.verify_signature([paymentId, currency, basketId, conversationId, paidPrice, price],secret_key, signature) \ No newline at end of file diff --git a/samples/create_threeds_payment.py b/samples/create_threeds_payment.py index 38e859e..c73de07 100644 --- a/samples/create_threeds_payment.py +++ b/samples/create_threeds_payment.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -13,6 +14,18 @@ 'conversationData': 'conversation data' } -threeds_payment = iyzipay.ThreedsPayment().create(request, options) +threeds_payment = iyzipay.ThreedsPayment() +threeds_payment_result = threeds_payment.create(request, options) +threeds_payment_response = json.load(threeds_payment_result) +print('response:', threeds_payment_response) -print(threeds_payment.read().decode('utf-8')) +if threeds_payment_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = threeds_payment_response['paymentId'] + currency = threeds_payment_response['currency'] + basketId = threeds_payment_response['basketId'] + conversationId = threeds_payment_response['conversationId'] + paidPrice = str(threeds_payment_response['paidPrice']) + price = str(threeds_payment_response['price']) + signature = threeds_payment_response['signature'] + threeds_payment.verify_signature([paymentId, currency, basketId, conversationId, paidPrice, price],secret_key, signature) \ No newline at end of file diff --git a/samples/initialize_bkm.py b/samples/initialize_bkm.py index 9632fbc..9dc13ea 100644 --- a/samples/initialize_bkm.py +++ b/samples/initialize_bkm.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -71,6 +72,14 @@ 'basketItems': basket_items } -bkm_initialize = iyzipay.BkmInitialize().create(request, options) +bkm_initialize = iyzipay.BkmInitialize() +bkm_initialize_result = bkm_initialize.create(request, options) +bkm_initialize_response = json.load(bkm_initialize_result) +print('response:', bkm_initialize_response) -print(bkm_initialize.read().decode('utf-8')) +if bkm_initialize_response['status'] == 'success': + secret_key = options['secret_key'] + conversationId = bkm_initialize_response['conversationId'] + token = bkm_initialize_response['token'] + signature = bkm_initialize_response['signature'] + bkm_initialize.verify_signature([token, conversationId], secret_key, signature) diff --git a/samples/initialize_checkout_form.py b/samples/initialize_checkout_form.py index 0841905..1f26e83 100644 --- a/samples/initialize_checkout_form.py +++ b/samples/initialize_checkout_form.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -73,6 +74,14 @@ 'basketItems': basket_items } -checkout_form_initialize = iyzipay.CheckoutFormInitialize().create(request, options) +checkout_form_initialize = iyzipay.CheckoutFormInitialize() +checkout_form_initialize_result = checkout_form_initialize.create(request, options) +checkout_form_initialize_response = json.load(checkout_form_initialize_result) +print('response:', checkout_form_initialize_response) -print(checkout_form_initialize.read().decode('utf-8')) +if checkout_form_initialize_response['status'] == 'success': + secret_key = options['secret_key'] + conversationId = checkout_form_initialize_response['conversationId'] + token = checkout_form_initialize_response['token'] + signature = checkout_form_initialize_response['signature'] + checkout_form_initialize.verify_signature([conversationId, token], secret_key, signature) diff --git a/samples/initialize_threeds.py b/samples/initialize_threeds.py index 96284ce..90e90fc 100644 --- a/samples/initialize_threeds.py +++ b/samples/initialize_threeds.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -84,6 +85,14 @@ 'basketItems': basket_items } -threeds_initialize = iyzipay.ThreedsInitialize().create(request, options) +threeds_initialize = iyzipay.ThreedsInitialize() +threeds_initialize_result = threeds_initialize.create(request, options) +threeds_initialize_response = json.load(threeds_initialize_result) +print('response:', threeds_initialize_response) -print(threeds_initialize.read().decode('utf-8')) +if threeds_initialize_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = threeds_initialize_response['paymentId'] + conversationId = threeds_initialize_response['conversationId'] + signature = threeds_initialize_response['signature'] + threeds_initialize.verify_signature([paymentId , conversationId], secret_key, signature) \ No newline at end of file diff --git a/samples/retrieve_bkm_result.py b/samples/retrieve_bkm_result.py index 2a69a6c..dce7d12 100644 --- a/samples/retrieve_bkm_result.py +++ b/samples/retrieve_bkm_result.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -9,9 +10,23 @@ request = { 'locale': 'tr', 'conversationId': '123456789', - 'token': 'token' + 'token': 'mockToken_1727280290715' } -bkm = iyzipay.Bkm().retrieve(request, options) +bkm = iyzipay.Bkm() +bkm_retrieve_result = bkm.retrieve(request, options) +bkm_retrieve_response = json.load(bkm_retrieve_result) +print('response:', bkm_retrieve_response) -print(bkm.read().decode('utf-8')) +if bkm_retrieve_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = bkm_retrieve_response['paymentId'] + paymentStatus = bkm_retrieve_response['paymentStatus'] + basketId = bkm_retrieve_response['basketId'] + conversationId = bkm_retrieve_response['conversationId'] + currency = bkm_retrieve_response['currency'] + paidPrice = str(bkm_retrieve_response['paidPrice']) + price = str(bkm_retrieve_response['price']) + token = bkm_retrieve_response['token'] + signature = bkm_retrieve_response['signature'] + bkm.verify_signature([paymentId, paymentStatus, basketId, conversationId, currency, paidPrice, price, token], secret_key, signature) \ No newline at end of file diff --git a/samples/retrieve_checkout_form_result.py b/samples/retrieve_checkout_form_result.py index f6f4e2d..5f0eb05 100644 --- a/samples/retrieve_checkout_form_result.py +++ b/samples/retrieve_checkout_form_result.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -12,6 +13,20 @@ 'token': 'token' } -checkout_form_result = iyzipay.CheckoutForm().retrieve(request, options) +checkout_form_retrieve = iyzipay.CheckoutForm() +checkout_form_retrieve_result = checkout_form_retrieve.retrieve(request, options) +checkout_form_retrieve_response = json.load(checkout_form_retrieve_result) +print('response:', checkout_form_retrieve_response) -print(checkout_form_result.read().decode('utf-8')) +if checkout_form_retrieve_response['status'] == 'success': + secret_key = options['secret_key'] + paymentStatus = checkout_form_retrieve_response['paymentStatus'] + paymentId = checkout_form_retrieve_response['paymentId'] + currency = checkout_form_retrieve_response['currency'] + basketId = checkout_form_retrieve_response['basketId'] + conversationId = checkout_form_retrieve_response['conversationId'] + paidPrice = str(checkout_form_retrieve_response['paidPrice']) + price = str(checkout_form_retrieve_response['price']) + token = checkout_form_retrieve_response['token'] + signature = checkout_form_retrieve_response['signature'] + checkout_form_retrieve.verify_signature([paymentStatus, paymentId, currency, basketId, conversationId, paidPrice, price, token], secret_key, signature) diff --git a/samples/retrieve_payment_result.py b/samples/retrieve_payment_result.py index 4cd7d27..a3f3fab 100644 --- a/samples/retrieve_payment_result.py +++ b/samples/retrieve_payment_result.py @@ -1,3 +1,4 @@ +import json import iyzipay options = { @@ -13,6 +14,18 @@ 'paymentConversationId': '123456789' } -payment = iyzipay.Payment().retrieve(request, options) +payment_retrieve = iyzipay.Payment() +payment_retrieve_result = payment_retrieve.retrieve(request, options) +payment_retrieve_response = json.load(payment_retrieve_result) +print('response:', payment_retrieve_response) -print(payment.read().decode('utf-8')) +if payment_retrieve_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = payment_retrieve_response['paymentId'] + currency = payment_retrieve_response['currency'] + basketId = payment_retrieve_response['basketId'] + conversationId = payment_retrieve_response['conversationId'] + paidPrice = payment_retrieve.strip_zero(str(payment_retrieve_response['paidPrice'])) + price = payment_retrieve.strip_zero(str(payment_retrieve_response['price'])) + signature = payment_retrieve_response['signature'] + payment_retrieve.verify_signature([paymentId, currency, basketId, conversationId, paidPrice, price], secret_key, signature) \ No newline at end of file From d0392aaadc79ca788ec14a2412ab0c488a836aaf Mon Sep 17 00:00:00 2001 From: Osman Keser Date: Thu, 26 Sep 2024 16:12:38 +0300 Subject: [PATCH 4/6] new service samples including signature verification added --- samples/create_payment_postauth.py | 33 +++++++ samples/create_payment_preauth.py | 101 ++++++++++++++++++++ samples/initialize_checkout_form_preauth.py | 86 +++++++++++++++++ samples/initialize_threeds_preauth.py | 98 +++++++++++++++++++ 4 files changed, 318 insertions(+) create mode 100644 samples/create_payment_postauth.py create mode 100644 samples/create_payment_preauth.py create mode 100644 samples/initialize_checkout_form_preauth.py create mode 100644 samples/initialize_threeds_preauth.py diff --git a/samples/create_payment_postauth.py b/samples/create_payment_postauth.py new file mode 100644 index 0000000..a2952c7 --- /dev/null +++ b/samples/create_payment_postauth.py @@ -0,0 +1,33 @@ +import json +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +request = { + 'locale': 'tr', + 'conversationId': '123456789', + 'paymentId': '1', + 'paidPrice': '1.2', + 'ip': '85.34.78.112', + 'currency': 'TRY' +} + +payment_postauth = iyzipay.PaymentPostAuth() +payment_postauth_result = payment_postauth.create(request, options) +payment_postauth_result_response = json.load(payment_postauth_result) +print('response:', payment_postauth_result_response) + +if payment_postauth_result_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = payment_postauth_result_response['paymentId'] + currency = payment_postauth_result_response['currency'] + basketId = payment_postauth_result_response['basketId'] + conversationId = payment_postauth_result_response['conversationId'] + paidPrice = payment_postauth.strip_zero(str(payment_postauth_result_response['paidPrice'])) + price = payment_postauth.strip_zero(str(payment_postauth_result_response['price'])) + signature = payment_postauth_result_response['signature'] + payment_postauth.verify_signature([paymentId, currency, basketId, conversationId, paidPrice, price], secret_key, signature) diff --git a/samples/create_payment_preauth.py b/samples/create_payment_preauth.py new file mode 100644 index 0000000..6c273c7 --- /dev/null +++ b/samples/create_payment_preauth.py @@ -0,0 +1,101 @@ +import json +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +payment_card = { + 'cardHolderName': 'John Doe', + 'cardNumber': '5528790000000008', + 'expireMonth': '12', + 'expireYear': '2030', + 'cvc': '123', + 'registerCard': '0' +} + +buyer = { + 'id': 'BY789', + 'name': 'John', + 'surname': 'Doe', + 'gsmNumber': '+905350000000', + 'email': 'email@email.com', + 'identityNumber': '74300864791', + 'lastLoginDate': '2015-10-05 12:43:35', + 'registrationDate': '2013-04-21 15:12:09', + 'registrationAddress': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', + 'ip': '85.34.78.112', + 'city': 'Istanbul', + 'country': 'Turkey', + 'zipCode': '34732' +} + +address = { + 'contactName': 'Jane Doe', + 'city': 'Istanbul', + 'country': 'Turkey', + 'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', + 'zipCode': '34732' +} + +basket_items = [ + { + 'id': 'BI101', + 'name': 'Binocular', + 'category1': 'Collectibles', + 'category2': 'Accessories', + 'itemType': 'PHYSICAL', + 'price': '0.3' + }, + { + 'id': 'BI102', + 'name': 'Game code', + 'category1': 'Game', + 'category2': 'Online Game Items', + 'itemType': 'VIRTUAL', + 'price': '0.5' + }, + { + 'id': 'BI103', + 'name': 'Usb', + 'category1': 'Electronics', + 'category2': 'Usb / Cable', + 'itemType': 'PHYSICAL', + 'price': '0.2' + } +] + +request = { + 'locale': 'tr', + 'conversationId': '123456789', + 'price': '1', + 'paidPrice': '1.2', + 'currency': 'TRY', + 'installment': '1', + 'basketId': 'B67832', + 'paymentChannel': 'WEB', + 'paymentGroup': 'PRODUCT', + 'paymentCard': payment_card, + 'buyer': buyer, + 'shippingAddress': address, + 'billingAddress': address, + 'basketItems': basket_items +} + +payment_preauth = iyzipay.PaymentPreAuth() +payment_preauth_result = payment_preauth.create(request, options) +payment_preauth_result_response = json.load(payment_preauth_result) +print('response:', payment_preauth_result_response) + +if payment_preauth_result_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = payment_preauth_result_response['paymentId'] + currency = payment_preauth_result_response['currency'] + basketId = payment_preauth_result_response['basketId'] + conversationId = payment_preauth_result_response['conversationId'] + paidPrice = payment_preauth.strip_zero(str(payment_preauth_result_response['paidPrice'])) + price = payment_preauth.strip_zero(str(payment_preauth_result_response['price'])) + signature = payment_preauth_result_response['signature'] + payment_preauth.verify_signature([paymentId, currency, basketId, conversationId, paidPrice, price],secret_key, signature) \ No newline at end of file diff --git a/samples/initialize_checkout_form_preauth.py b/samples/initialize_checkout_form_preauth.py new file mode 100644 index 0000000..f93fded --- /dev/null +++ b/samples/initialize_checkout_form_preauth.py @@ -0,0 +1,86 @@ +import json +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +buyer = { + 'id': 'BY789', + 'name': 'John', + 'surname': 'Doe', + 'gsmNumber': '+905350000000', + 'email': 'email@email.com', + 'identityNumber': '74300864791', + 'lastLoginDate': '2015-10-05 12:43:35', + 'registrationDate': '2013-04-21 15:12:09', + 'registrationAddress': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', + 'ip': '85.34.78.112', + 'city': 'Istanbul', + 'country': 'Turkey', + 'zipCode': '34732' +} + +address = { + 'contactName': 'Jane Doe', + 'city': 'Istanbul', + 'country': 'Turkey', + 'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', + 'zipCode': '34732' +} + +basket_items = [ + { + 'id': 'BI101', + 'name': 'Binocular', + 'category1': 'Collectibles', + 'category2': 'Accessories', + 'itemType': 'PHYSICAL', + 'price': '0.3' + }, + { + 'id': 'BI102', + 'name': 'Game code', + 'category1': 'Game', + 'category2': 'Online Game Items', + 'itemType': 'VIRTUAL', + 'price': '0.5' + }, + { + 'id': 'BI103', + 'name': 'Usb', + 'category1': 'Electronics', + 'category2': 'Usb / Cable', + 'itemType': 'PHYSICAL', + 'price': '0.2' + } +] + +request = { + 'locale': 'tr', + 'conversationId': '123456789', + 'price': '1', + 'paidPrice': '1.2', + 'currency': 'TRY', + 'basketId': 'B67832', + 'paymentGroup': 'PRODUCT', + "callbackUrl": "https://www.merchant.com/callback", + 'buyer': buyer, + 'shippingAddress': address, + 'billingAddress': address, + 'basketItems': basket_items +} + +checkout_form_preauth_initialize = iyzipay.CheckoutFormInitialize() +checkout_form_preauth_initialize_result = checkout_form_preauth_initialize.create(request, options) +checkout_form_preauth_initialize_response = json.load(checkout_form_preauth_initialize_result) +print('response:', checkout_form_preauth_initialize_response) + +if checkout_form_preauth_initialize_response['status'] == 'success': + secret_key = options['secret_key'] + conversationId = checkout_form_preauth_initialize_response['conversationId'] + token = checkout_form_preauth_initialize_response['token'] + signature = checkout_form_preauth_initialize_response['signature'] + checkout_form_preauth_initialize.verify_signature([conversationId, token], secret_key, signature) diff --git a/samples/initialize_threeds_preauth.py b/samples/initialize_threeds_preauth.py new file mode 100644 index 0000000..cca3df6 --- /dev/null +++ b/samples/initialize_threeds_preauth.py @@ -0,0 +1,98 @@ +import json +import iyzipay + +options = { + 'api_key': iyzipay.api_key, + 'secret_key': iyzipay.secret_key, + 'base_url': iyzipay.base_url +} + +payment_card = { + 'cardHolderName': 'John Doe', + 'cardNumber': '5528790000000008', + 'expireMonth': '12', + 'expireYear': '2030', + 'cvc': '123', + 'registerCard': '0' +} + +buyer = { + 'id': 'BY789', + 'name': 'John', + 'surname': 'Doe', + 'gsmNumber': '+905350000000', + 'email': 'email@email.com', + 'identityNumber': '74300864791', + 'lastLoginDate': '2015-10-05 12:43:35', + 'registrationDate': '2013-04-21 15:12:09', + 'registrationAddress': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', + 'ip': '85.34.78.112', + 'city': 'Istanbul', + 'country': 'Turkey', + 'zipCode': '34732' +} + +address = { + 'contactName': 'Jane Doe', + 'city': 'Istanbul', + 'country': 'Turkey', + 'address': 'Nidakule Göztepe, Merdivenköy Mah. Bora Sok. No:1', + 'zipCode': '34732' +} + +basket_items = [ + { + 'id': 'BI101', + 'name': 'Binocular', + 'category1': 'Collectibles', + 'category2': 'Accessories', + 'itemType': 'PHYSICAL', + 'price': '0.3' + }, + { + 'id': 'BI102', + 'name': 'Game code', + 'category1': 'Game', + 'category2': 'Online Game Items', + 'itemType': 'VIRTUAL', + 'price': '0.5' + }, + { + 'id': 'BI103', + 'name': 'Usb', + 'category1': 'Electronics', + 'category2': 'Usb / Cable', + 'itemType': 'PHYSICAL', + 'price': '0.2' + } +] + +request = { + 'locale': 'tr', + 'conversationId': '123456789', + 'price': '1', + 'paidPrice': '1.2', + 'currency': 'TRY', + 'installment': '1', + 'basketId': 'B67832', + 'paymentChannel': 'WEB', + 'paymentGroup': 'PRODUCT', + "callbackUrl": "https://www.merchant.com/callback", + 'paymentCard': payment_card, + 'buyer': buyer, + 'shippingAddress': address, + 'billingAddress': address, + 'basketItems': basket_items +} + +threeds_initialize_preauth = iyzipay.ThreedsInitializePreAuth() +threeds_initialize_preauth_result = threeds_initialize_preauth.create(request, options) +threeds_initialize_preauth_response = json.load(threeds_initialize_preauth_result) +print('response:', threeds_initialize_preauth_response) + +if threeds_initialize_preauth_response['status'] == 'success': + secret_key = options['secret_key'] + paymentId = threeds_initialize_preauth_response['paymentId'] + conversationId = threeds_initialize_preauth_response['conversationId'] + signature = threeds_initialize_preauth_response['signature'] + threeds_initialize_preauth.verify_signature([paymentId , conversationId], secret_key, signature) \ No newline at end of file From 806526b8bc356b464ff14b0a9a47107564bad92f Mon Sep 17 00:00:00 2001 From: Osman Keser Date: Fri, 27 Sep 2024 12:19:05 +0300 Subject: [PATCH 5/6] Supported versions update --- setup.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index ac333d3..1594d1e 100755 --- a/setup.py +++ b/setup.py @@ -34,10 +34,13 @@ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", - "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules", ], From 8e54f543c3d2d43fedb9e18e8753af55c7dce9d9 Mon Sep 17 00:00:00 2001 From: byasarcse Date: Wed, 30 Oct 2024 13:55:47 +0300 Subject: [PATCH 6/6] SignatureStrip&CheckoutformPreAuth Modified --- samples/create_threeds_payment.py | 6 +++--- samples/initialize_checkout_form_preauth.py | 2 +- samples/retrieve_bkm_result.py | 4 ++-- samples/retrieve_checkout_form_result.py | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/samples/create_threeds_payment.py b/samples/create_threeds_payment.py index c73de07..dadb7e4 100644 --- a/samples/create_threeds_payment.py +++ b/samples/create_threeds_payment.py @@ -11,7 +11,7 @@ 'locale': 'tr', 'conversationId': '123456789', 'paymentId': '1', - 'conversationData': 'conversation data' + 'conversationData': '' } threeds_payment = iyzipay.ThreedsPayment() @@ -25,7 +25,7 @@ currency = threeds_payment_response['currency'] basketId = threeds_payment_response['basketId'] conversationId = threeds_payment_response['conversationId'] - paidPrice = str(threeds_payment_response['paidPrice']) - price = str(threeds_payment_response['price']) + paidPrice = threeds_payment.strip_zero(str(threeds_payment_response['paidPrice'])) + price = threeds_payment.strip_zero(str(threeds_payment_response['price'])) signature = threeds_payment_response['signature'] threeds_payment.verify_signature([paymentId, currency, basketId, conversationId, paidPrice, price],secret_key, signature) \ No newline at end of file diff --git a/samples/initialize_checkout_form_preauth.py b/samples/initialize_checkout_form_preauth.py index f93fded..9d62773 100644 --- a/samples/initialize_checkout_form_preauth.py +++ b/samples/initialize_checkout_form_preauth.py @@ -73,7 +73,7 @@ 'basketItems': basket_items } -checkout_form_preauth_initialize = iyzipay.CheckoutFormInitialize() +checkout_form_preauth_initialize = iyzipay.CheckoutFormInitializePreAuth() checkout_form_preauth_initialize_result = checkout_form_preauth_initialize.create(request, options) checkout_form_preauth_initialize_response = json.load(checkout_form_preauth_initialize_result) print('response:', checkout_form_preauth_initialize_response) diff --git a/samples/retrieve_bkm_result.py b/samples/retrieve_bkm_result.py index dce7d12..f355a6e 100644 --- a/samples/retrieve_bkm_result.py +++ b/samples/retrieve_bkm_result.py @@ -25,8 +25,8 @@ basketId = bkm_retrieve_response['basketId'] conversationId = bkm_retrieve_response['conversationId'] currency = bkm_retrieve_response['currency'] - paidPrice = str(bkm_retrieve_response['paidPrice']) - price = str(bkm_retrieve_response['price']) + paidPrice = bkm.strip_zero(str(bkm_retrieve_response['paidPrice'])) + price = bkm.strip_zero(str(bkm_retrieve_response['price'])) token = bkm_retrieve_response['token'] signature = bkm_retrieve_response['signature'] bkm.verify_signature([paymentId, paymentStatus, basketId, conversationId, currency, paidPrice, price, token], secret_key, signature) \ No newline at end of file diff --git a/samples/retrieve_checkout_form_result.py b/samples/retrieve_checkout_form_result.py index 5f0eb05..14057a8 100644 --- a/samples/retrieve_checkout_form_result.py +++ b/samples/retrieve_checkout_form_result.py @@ -25,8 +25,8 @@ currency = checkout_form_retrieve_response['currency'] basketId = checkout_form_retrieve_response['basketId'] conversationId = checkout_form_retrieve_response['conversationId'] - paidPrice = str(checkout_form_retrieve_response['paidPrice']) - price = str(checkout_form_retrieve_response['price']) + paidPrice = checkout_form_retrieve.strip_zero(str(checkout_form_retrieve_response['paidPrice'])) + price = checkout_form_retrieve.strip_zero(str(checkout_form_retrieve_response['price'])) token = checkout_form_retrieve_response['token'] signature = checkout_form_retrieve_response['signature'] checkout_form_retrieve.verify_signature([paymentStatus, paymentId, currency, basketId, conversationId, paidPrice, price, token], secret_key, signature)