Skip to content

Commit

Permalink
bnpl payment integration (#92)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
deryacakmak and MasterSlave authored Nov 14, 2023
1 parent fda4260 commit 90ef3f2
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 0 deletions.
8 changes: 8 additions & 0 deletions samples/approve_bnpl_payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

require_once('config/sample_config.php');


$response = SampleConfig::craftgate()->payment()->approveBnplPayment(1);

print_r($response);
35 changes: 35 additions & 0 deletions samples/bnpl_payment_offer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

require_once('config/sample_config.php');

use Craftgate\Model\ApmType;
use Craftgate\Model\BnplCartItemType;
use Craftgate\Model\Currency;

$request = array(
'apmType' => 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);
56 changes: 56 additions & 0 deletions samples/init_bnpl_payment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

require_once('config/sample_config.php');

use Craftgate\Model\ApmType;
use Craftgate\Model\BnplCartItemType;
use Craftgate\Model\Currency;
use Craftgate\Model\PaymentGroup;
use Craftgate\Util\Guid;

$request = array(
'price' => 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);
18 changes: 18 additions & 0 deletions src/Adapter/PaymentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
2 changes: 2 additions & 0 deletions src/Model/ApmType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
30 changes: 30 additions & 0 deletions src/Model/BnplCartItemType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Craftgate\Model;

class BnplCartItemType
{
const MOBILE_PHONE_OVER_5000_TRY = 'MOBILE_PHONE_OVER_5000_TRY';
const MOBILE_PHONE_BELOW_5000_TRY = 'PAYONEER';
const TABLET = 'TABLET';
const COMPUTER = 'COMPUTER';
const CONSTRUCTION_MARKET = 'CONSTRUCTION_MARKET';
const GOLD = 'GOLD';
const DIGITAL_PRODUCTS = 'DIGITAL_PRODUCTS';
const SUPERMARKET = 'SUPERMARKET';
const WHITE_GOODS = 'WHITE_GOODS';
const WEARABLE_TECHNOLOGY = 'WEARABLE_TECHNOLOGY';
const SMALL_HOME_APPLIANCES = 'SMALL_HOME_APPLIANCES';
const TV = 'TV';
const GAMES_CONSOLES = 'GAMES_CONSOLES';
const AIR_CONDITIONER_AND_HEATER = 'AIR_CONDITIONER_AND_HEATER';
const ELECTRONICS = 'ELECTRONICS';
const MOM_AND_BABY_AND_KIDS = 'MOM_AND_BABY_AND_KIDS';
const SHOES = 'SHOES';
const CLOTHING = 'CLOTHING';
const COSMETICS_AND_PERSONAL_CARE = 'COSMETICS_AND_PERSONAL_CARE';
const FURNITURE = 'FURNITURE';
const HOME_LIVING = 'HOME_LIVING';
const AUTOMOBILE_MOTORCYCLE = 'AUTOMOBILE_MOTORCYCLE';
const OTHER = 'OTHER';
}

0 comments on commit 90ef3f2

Please sign in to comment.