diff --git a/iyzipay/iyzipay_resource.py b/iyzipay/iyzipay_resource.py index be806ed..83770a5 100644 --- a/iyzipay/iyzipay_resource.py +++ b/iyzipay/iyzipay_resource.py @@ -8,13 +8,13 @@ import string import iyzipay - +from iyzipay.iyzipay_response import IyzipayResponse 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' } @@ -27,7 +27,11 @@ def connect(self, method, url, options, request_body_dict=None, pki=None): body_str = json.dumps(request_body_dict) header = self.get_http_header(url, options, body_str, pki) connection.request(method, url, body_str, header) - return connection.getresponse() + try: + body = json.loads(response.read().decode('utf-8')) + except: + body = None + return IyzipayResponse(response.status, body) def get_http_header(self, url, options=None, body_str=None, pki_string=None): random_str = self.generate_random_string(self.RANDOM_STRING_SIZE) @@ -856,7 +860,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') @@ -873,7 +877,7 @@ 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') diff --git a/iyzipay/iyzipay_response.py b/iyzipay/iyzipay_response.py new file mode 100644 index 0000000..a4ad927 --- /dev/null +++ b/iyzipay/iyzipay_response.py @@ -0,0 +1,3 @@ +from collections import namedtuple + +IyzipayResponse = namedtuple('IyzipayResponse', ('status', 'body')) diff --git a/samples/api_test.py b/samples/api_test.py index f55c7a1..3f3038b 100644 --- a/samples/api_test.py +++ b/samples/api_test.py @@ -6,4 +6,4 @@ api_test = iyzipay.ApiTest().retrieve(options) -print(api_test.read().decode('utf-8')) +print(api_test.body) diff --git a/samples/approve.py b/samples/approve.py index d758351..278026c 100644 --- a/samples/approve.py +++ b/samples/approve.py @@ -14,4 +14,4 @@ approval = iyzipay.Approval().create(request, options) -print(approval.read().decode('utf-8')) +print(approval.body) diff --git a/samples/cancel.py b/samples/cancel.py index 75ca3f4..b4dc18f 100644 --- a/samples/cancel.py +++ b/samples/cancel.py @@ -17,4 +17,4 @@ cancel = iyzipay.Cancel().create(request, options) -print(cancel.read().decode('utf-8')) +print(cancel.body) diff --git a/samples/create_card.py b/samples/create_card.py index b555429..69772c7 100644 --- a/samples/create_card.py +++ b/samples/create_card.py @@ -23,4 +23,4 @@ card = iyzipay.Card().create(request, options) -print(card.read().decode('utf-8')) +print(card.body) diff --git a/samples/create_limited_company_sub_merchant.py b/samples/create_limited_company_sub_merchant.py index 2e1210d..b2fb111 100644 --- a/samples/create_limited_company_sub_merchant.py +++ b/samples/create_limited_company_sub_merchant.py @@ -24,4 +24,4 @@ sub_merchant = iyzipay.SubMerchant().create(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body) diff --git a/samples/create_marketplace_payment.py b/samples/create_marketplace_payment.py index 8af82a2..acfa11a 100644 --- a/samples/create_marketplace_payment.py +++ b/samples/create_marketplace_payment.py @@ -91,4 +91,4 @@ payment = iyzipay.Payment().create(request, options) -print(payment.read().decode('utf-8')) +print(payment.body) diff --git a/samples/create_payment.py b/samples/create_payment.py index 5c41e07..5d2597b 100644 --- a/samples/create_payment.py +++ b/samples/create_payment.py @@ -85,4 +85,4 @@ payment = iyzipay.Payment().create(request, options) -print(payment.read().decode('utf-8')) +print(payment.body) diff --git a/samples/create_payment_with_registered_card.py b/samples/create_payment_with_registered_card.py index f259a4e..aff8e14 100644 --- a/samples/create_payment_with_registered_card.py +++ b/samples/create_payment_with_registered_card.py @@ -81,4 +81,4 @@ payment = iyzipay.Payment().create(request, options) -print(payment.read().decode('utf-8')) +print(payment.body) diff --git a/samples/create_pecco_payment.py b/samples/create_pecco_payment.py index f5f276e..2f03df5 100644 --- a/samples/create_pecco_payment.py +++ b/samples/create_pecco_payment.py @@ -14,4 +14,4 @@ pecco_payment = iyzipay.PeccoPayment().create(request, options) -print(pecco_payment.read().decode('utf-8')) +print(pecco_payment.body) diff --git a/samples/create_personal_sub_merchant.py b/samples/create_personal_sub_merchant.py index be779be..3d75c9c 100644 --- a/samples/create_personal_sub_merchant.py +++ b/samples/create_personal_sub_merchant.py @@ -24,4 +24,4 @@ sub_merchant = iyzipay.SubMerchant().create(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body) diff --git a/samples/create_private_sub_merchant.py b/samples/create_private_sub_merchant.py index ef9d104..37c6876 100644 --- a/samples/create_private_sub_merchant.py +++ b/samples/create_private_sub_merchant.py @@ -24,4 +24,4 @@ sub_merchant = iyzipay.SubMerchant().create(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body) diff --git a/samples/create_threeds_payment.py b/samples/create_threeds_payment.py index 38e859e..0c6082d 100644 --- a/samples/create_threeds_payment.py +++ b/samples/create_threeds_payment.py @@ -15,4 +15,4 @@ threeds_payment = iyzipay.ThreedsPayment().create(request, options) -print(threeds_payment.read().decode('utf-8')) +print(threeds_payment.body) diff --git a/samples/create_user_and_card.py b/samples/create_user_and_card.py index f8b58c6..528a76d 100644 --- a/samples/create_user_and_card.py +++ b/samples/create_user_and_card.py @@ -24,4 +24,4 @@ card = iyzipay.Card().create(request, options) -print(card.read().decode('utf-8')) +print(card.body) diff --git a/samples/delete_card.py b/samples/delete_card.py index 965137e..5006455 100644 --- a/samples/delete_card.py +++ b/samples/delete_card.py @@ -15,4 +15,4 @@ card = iyzipay.Card().delete(request, options) -print(card.read().decode('utf-8')) +print(card.body) diff --git a/samples/disapprove.py b/samples/disapprove.py index ee4a402..3379038 100644 --- a/samples/disapprove.py +++ b/samples/disapprove.py @@ -14,4 +14,4 @@ disapproval = iyzipay.Disapproval().create(request, options) -print(disapproval.read().decode('utf-8')) +print(disapproval.body) diff --git a/samples/initialize_bkm.py b/samples/initialize_bkm.py index 9632fbc..cf063e4 100644 --- a/samples/initialize_bkm.py +++ b/samples/initialize_bkm.py @@ -73,4 +73,4 @@ bkm_initialize = iyzipay.BkmInitialize().create(request, options) -print(bkm_initialize.read().decode('utf-8')) +print(bkm_initialize.body) diff --git a/samples/initialize_checkout_form.py b/samples/initialize_checkout_form.py index ef60c4a..4f1f7b1 100644 --- a/samples/initialize_checkout_form.py +++ b/samples/initialize_checkout_form.py @@ -76,4 +76,4 @@ checkout_form_initialize = iyzipay.CheckoutFormInitialize().create(request, options) -print(checkout_form_initialize.read().decode('utf-8')) +print(checkout_form_initialize.body) diff --git a/samples/initialize_pecco.py b/samples/initialize_pecco.py index c438037..737d17f 100644 --- a/samples/initialize_pecco.py +++ b/samples/initialize_pecco.py @@ -74,4 +74,4 @@ pecco_initialize = iyzipay.PeccoInitialize().create(request, options) -print(pecco_initialize.read().decode('utf-8')) +print(pecco_initialize.body) diff --git a/samples/initialize_threeds.py b/samples/initialize_threeds.py index 96284ce..fa6b3fc 100644 --- a/samples/initialize_threeds.py +++ b/samples/initialize_threeds.py @@ -86,4 +86,4 @@ threeds_initialize = iyzipay.ThreedsInitialize().create(request, options) -print(threeds_initialize.read().decode('utf-8')) +print(threeds_initialize.body) diff --git a/samples/refund.py b/samples/refund.py index 8e7bb53..40cca48 100644 --- a/samples/refund.py +++ b/samples/refund.py @@ -19,4 +19,4 @@ refund = iyzipay.Refund().create(request, options) -print(refund.read().decode('utf-8')) +print(refund.body) diff --git a/samples/retrieve_bin.py b/samples/retrieve_bin.py index 11c3efa..ab94e48 100644 --- a/samples/retrieve_bin.py +++ b/samples/retrieve_bin.py @@ -14,4 +14,4 @@ bin_number = iyzipay.BinNumber().retrieve(request, options) -print(bin_number.read().decode('utf-8')) +print(bin_number.body) diff --git a/samples/retrieve_bkm_result.py b/samples/retrieve_bkm_result.py index 2a69a6c..803d231 100644 --- a/samples/retrieve_bkm_result.py +++ b/samples/retrieve_bkm_result.py @@ -14,4 +14,4 @@ bkm = iyzipay.Bkm().retrieve(request, options) -print(bkm.read().decode('utf-8')) +print(bkm.body) diff --git a/samples/retrieve_bounced_bank_transfers.py b/samples/retrieve_bounced_bank_transfers.py index a36d115..68ba6c9 100644 --- a/samples/retrieve_bounced_bank_transfers.py +++ b/samples/retrieve_bounced_bank_transfers.py @@ -14,4 +14,4 @@ bounced_bank_transfer_list = iyzipay.BouncedBankTransferList().retrieve(request, options) -print(bounced_bank_transfer_list.read().decode('utf-8')) +print(bounced_bank_transfer_list.body) diff --git a/samples/retrieve_cards.py b/samples/retrieve_cards.py index a86575f..2835ee5 100644 --- a/samples/retrieve_cards.py +++ b/samples/retrieve_cards.py @@ -14,4 +14,4 @@ card_list = iyzipay.CardList().retrieve(request, options) -print(card_list.read().decode('utf-8')) +print(card_list.body) diff --git a/samples/retrieve_checkout_form_result.py b/samples/retrieve_checkout_form_result.py index f6f4e2d..31dc582 100644 --- a/samples/retrieve_checkout_form_result.py +++ b/samples/retrieve_checkout_form_result.py @@ -14,4 +14,4 @@ checkout_form_result = iyzipay.CheckoutForm().retrieve(request, options) -print(checkout_form_result.read().decode('utf-8')) +print(checkout_form_result.body) diff --git a/samples/retrieve_installments.py b/samples/retrieve_installments.py index 44fa98d..75c2d31 100644 --- a/samples/retrieve_installments.py +++ b/samples/retrieve_installments.py @@ -15,4 +15,4 @@ installment_info = iyzipay.InstallmentInfo().retrieve(request, options) -print(installment_info.read().decode('utf-8')) +print(installment_info.body) diff --git a/samples/retrieve_payment_result.py b/samples/retrieve_payment_result.py index 4cd7d27..99eabf1 100644 --- a/samples/retrieve_payment_result.py +++ b/samples/retrieve_payment_result.py @@ -15,4 +15,4 @@ payment = iyzipay.Payment().retrieve(request, options) -print(payment.read().decode('utf-8')) +print(payment.body) diff --git a/samples/retrieve_payout_completed_transactions.py b/samples/retrieve_payout_completed_transactions.py index 82e505a..40c9009 100644 --- a/samples/retrieve_payout_completed_transactions.py +++ b/samples/retrieve_payout_completed_transactions.py @@ -14,4 +14,4 @@ payout_completed_transaction_list = iyzipay.PayoutCompletedTransactionList().retrieve(request, options) -print(payout_completed_transaction_list.read().decode('utf-8')) +print(payout_completed_transaction_list.body) diff --git a/samples/retrieve_sub_merchant.py b/samples/retrieve_sub_merchant.py index 2d71d7a..c35167f 100644 --- a/samples/retrieve_sub_merchant.py +++ b/samples/retrieve_sub_merchant.py @@ -14,4 +14,4 @@ sub_merchant = iyzipay.SubMerchant().retrieve(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body) diff --git a/samples/update_limited_company_sub_merchant.py b/samples/update_limited_company_sub_merchant.py index cc22246..4b8ebb1 100644 --- a/samples/update_limited_company_sub_merchant.py +++ b/samples/update_limited_company_sub_merchant.py @@ -23,4 +23,4 @@ sub_merchant = iyzipay.SubMerchant().update(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body) diff --git a/samples/update_personal_sub_merchant.py b/samples/update_personal_sub_merchant.py index f787422..086123b 100644 --- a/samples/update_personal_sub_merchant.py +++ b/samples/update_personal_sub_merchant.py @@ -23,4 +23,4 @@ sub_merchant = iyzipay.SubMerchant().update(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body) diff --git a/samples/update_private_sub_merchant.py b/samples/update_private_sub_merchant.py index 4f86ba7..4486625 100644 --- a/samples/update_private_sub_merchant.py +++ b/samples/update_private_sub_merchant.py @@ -23,4 +23,4 @@ sub_merchant = iyzipay.SubMerchant().update(request, options) -print(sub_merchant.read().decode('utf-8')) +print(sub_merchant.body)