Skip to content

Commit

Permalink
setup kbank sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
necessarylion committed Aug 8, 2021
0 parents commit b8c794b
Show file tree
Hide file tree
Showing 11 changed files with 1,321 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor
.env
.DS_Store
114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#### USAGE

<strong>`paymentType`</strong>\
(Possible Payment Type)

- qr
- alipay
- unionpay
- card

<strong>`dccCurrency`</strong> (Optional)\
Other Currency. Example - (USD)

<strong>`amount`</strong>\
Amount to charge. Example - (100)

<strong>`currency`</strong>\
Currency. Example - (THB) currently kbank only support THB

<strong>`description`</strong>\
Order Description.

<strong>`referenceOrder`</strong>\
Unique Order Number.

<strong>`token`</strong> (Optional)\
Request Token for Card (required only for card payment)

<strong>`getRedirectUrl()`</strong>\
Get redirect url for `alipay`, `card` and `unionpay` payment methods

<strong>`getQRPaymentOrderId()`</strong>\
Get redirect orderDetail for `thai qr` payment method

<strong>`getCharge($chargeId)`</strong>\
Get change detail for all kind of payments including qr

---

###### Example Usage

```
<?php
use Bilions\Kbank;
require __DIR__ . "/vendor/autoload.php";
$config = [
'KBANK_BASE_URL' => $_ENV['KBANK_BASE_URL'],
'KBANK_API_KEY' => $_ENV['KBANK_API_KEY'],
'KBANK_MID' => $_ENV['KBANK_MID'],
'KBANK_TID' => $_ENV['KBANK_TID'],
];
$kbank = new Kbank($config);
$kbank->paymentType = 'qr';
$kbank->amount = 100;
$kbank->currency = 'THB';
$kbank->description = 'Description Here';
$kbank->referenceOrder = uniqid();
$kbank->token = '{your-request-token-here}'; // only for card payment
$result = $kbank->getRedirectUrl();
$result = $kbank->getQRPaymentOrderId();
$result = $kbank->getCharge('{your-request-token-here}');
print_r($result);
```

###### QR Front End

```
<form method="POST" action="/payment/qr">
<script type="text/javascript"
src="https://dev-kpaymentgateway.kasikornbank.com/ui/v2/kpayment.min.js"
data-apikey="{{apiKey}}"
data-amount="{{price}}"
data-payment-methods="qr"
data-order-id="{{orderId}}"
data-name="Your Company Name"
data-show-button="false"
>
</script>
</form>
$(document).ready(function() {
KPayment.show()
})
```

###### Card Front End

```
<form id="form" method="POST" action="/api/payment/card">
<script type="text/javascript"
src="https://dev-kpaymentgateway.kasikornbank.com/ui/v2/kpayment.min.js"
data-apikey="{{apiKey}}"
data-amount="{{price}}"
data-currency="THB"
data-payment-methods="card"
data-name="Your Company Name"
data-show-button="false"
data-mid="{{mid}}">
</script>
<button class="pay-button" type="button" onclick="KPayment.show()">
<span class="btn-text">Credit / Debit Card</span>
</button>
</form>
```

###### Other Payment method

- for other payment method you can just redirect url
21 changes: 21 additions & 0 deletions TEST.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Bilions\Kbank;

require __DIR__ . "/vendor/autoload.php";

$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
$dotenv->load();

$kbank = new Kbank($_ENV);
$kbank->paymentType = 'qr'; // alipay
$kbank->amount = 100;
$kbank->currency = 'THB';
$kbank->description = 'Description';
$kbank->referenceOrder = uniqid();
$kbank->token = '{your-request-token-here}'; // only for card payment

// $result = $kbank->getRedirectUrl();
// $result = $kbank->getQRPaymentOrderId();
$result = $kbank->getCharge('{your-request-token-here}');
print_r($result->id);
19 changes: 19 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "bilions/kbank-sdk",
"description": "Thailand KBank SDK PHP",
"type": "sdk",
"license": "MIT",
"authors": [
{
"name": "AJ",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {"Bilions\\": "src/"}
},
"require": {
"guzzlehttp/guzzle": "^7.3",
"vlucas/phpdotenv": "^5.3"
}
}
Loading

0 comments on commit b8c794b

Please sign in to comment.