From 90ef3f24570a5d31a72d884439091067b1496ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Derya=20=C3=87akmak?= <36774966+deryacakmak@users.noreply.github.com> Date: Tue, 14 Nov 2023 14:31:36 +0200 Subject: [PATCH] bnpl payment integration (#92) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bnpl payment integration * bnpl payment integration * updates based on comments * updates based on comments * updates based on comments * rename file name * updates based on comments --------- Co-authored-by: Burak Baldırlıoğlu --- samples/approve_bnpl_payment.php | 8 +++++ samples/bnpl_payment_offer.php | 35 ++++++++++++++++++++ samples/init_bnpl_payment.php | 56 ++++++++++++++++++++++++++++++++ src/Adapter/PaymentAdapter.php | 18 ++++++++++ src/Model/ApmType.php | 2 ++ src/Model/BnplCartItemType.php | 30 +++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 samples/approve_bnpl_payment.php create mode 100644 samples/bnpl_payment_offer.php create mode 100644 samples/init_bnpl_payment.php create mode 100644 src/Model/BnplCartItemType.php diff --git a/samples/approve_bnpl_payment.php b/samples/approve_bnpl_payment.php new file mode 100644 index 0000000..1ee3cb8 --- /dev/null +++ b/samples/approve_bnpl_payment.php @@ -0,0 +1,8 @@ +payment()->approveBnplPayment(1); + +print_r($response); diff --git a/samples/bnpl_payment_offer.php b/samples/bnpl_payment_offer.php new file mode 100644 index 0000000..6075eac --- /dev/null +++ b/samples/bnpl_payment_offer.php @@ -0,0 +1,35 @@ + ApmType::MASLAK, + 'price' => 10000, + 'currency' => Currency::TL, + 'items' => array( + array( + 'id' => '200', + 'name' => 'Test Elektronik 2', + 'brandName' => 'iphone', + 'type' => BnplCartItemType::OTHER, + 'unitPrice' => 3000, + 'quantity' => 2, + ), + array( + 'id' => '100', + 'name' => 'Test Elektronik 1', + 'brandName' => 'Samsung', + 'type' => BnplCartItemType::MOBILE_PHONE_OVER_5000_TRY, + 'unitPrice' => 4000, + 'quantity' => 1, + ) + ) +); + +$response = SampleConfig::craftgate()->payment()->retrieveBnplOffers($request); + +print_r($response); \ No newline at end of file diff --git a/samples/init_bnpl_payment.php b/samples/init_bnpl_payment.php new file mode 100644 index 0000000..3bc3b8f --- /dev/null +++ b/samples/init_bnpl_payment.php @@ -0,0 +1,56 @@ + 10000, + 'paidPrice' => 10000, + 'currency' => Currency::TL, + 'apmType' => ApmType::MASLAK, + 'apmOrderId' => Guid::generate(), + 'paymentGroup' => PaymentGroup::PRODUCT, + 'externalId' => Guid::generate(), + 'conversationId' => '456d1297-908e-4bd6-a13b-4be31a6e47d5', + 'callbackUrl' => 'callbackUrl', + 'bankCode' => '103', + 'items' => array( + array( + 'externalId' => '38983903', + 'name' => 'Item 1', + 'price' => 6000, + ), + array( + 'externalId' => '92983294', + 'name' => 'Item 2', + 'price' => 4000, + ) + ), + 'cartItems' => array( + array( + 'id' => '200', + 'name' => 'Test Elektronik 2', + 'brandName' => 'iphone', + 'type' => BnplCartItemType::OTHER, + 'unitPrice' => 3000, + 'quantity' => 2, + ), + array( + 'id' => '100', + 'name' => 'Test Elektronik 1', + 'brandName' => 'Samsung', + 'type' => BnplCartItemType::MOBILE_PHONE_OVER_5000_TRY, + 'unitPrice' => 4000, + 'quantity' => 1, + ) + ) +); + +$response = SampleConfig::craftgate()->payment()->initBnplPayment($request); + +print_r($response); \ No newline at end of file diff --git a/src/Adapter/PaymentAdapter.php b/src/Adapter/PaymentAdapter.php index 516a81f..ff3a00e 100644 --- a/src/Adapter/PaymentAdapter.php +++ b/src/Adapter/PaymentAdapter.php @@ -199,6 +199,24 @@ public function createApplePayMerchantSession(array $request) return $this->httpPost($path, $request); } + public function retrieveBnplOffers(array $request) + { + $path = "/payment/v1/bnpl-payments/offers"; + return $this->httpPost($path, $request); + } + + public function initBnplPayment(array $request) + { + $path = "/payment/v1/bnpl-payments/init"; + return $this->httpPost($path, $request); + } + + public function approveBnplPayment($paymentId) + { + $path = "/payment/v1/bnpl-payments/" . $paymentId . "/approve"; + return $this->httpPost($path); + } + public function is3DSecureCallbackVerified($threeDSecureCallbackKey, $params) { $hash = $params["hash"]; diff --git a/src/Model/ApmType.php b/src/Model/ApmType.php index af9d373..769ebfe 100644 --- a/src/Model/ApmType.php +++ b/src/Model/ApmType.php @@ -15,6 +15,8 @@ class ApmType const STRIPE = 'STRIPE'; const KASPI = 'KASPI'; const TOMPAY = 'TOMPAY'; + const MASLAK = 'MASLAK'; + const ALFABANK = 'ALFABANK'; const FUND_TRANSFER = 'FUND_TRANSFER'; const CASH_ON_DELIVERY = 'CASH_ON_DELIVERY'; } diff --git a/src/Model/BnplCartItemType.php b/src/Model/BnplCartItemType.php new file mode 100644 index 0000000..d5cf683 --- /dev/null +++ b/src/Model/BnplCartItemType.php @@ -0,0 +1,30 @@ +