ด้วย BESTA COIN Standard และ Express คุณรับชำระเงินออนไลน์จากลูกค้าได้อย่างง่ายและปลอดภัย
หากผู้ชำระต้องการใช้ BESTA COIN ให้ตั้งผู้ชำระเป็น BESTA COIN (วิธีอื่น เช่น paypal, stripe, coin payments ฯลฯ ยังไม่พร้อมใช้งาน)
//Payer Object
$payer = new Payer();
$payer->setPaymentMethod('PayMoney'); //preferably, your system name, example - PayMoney
ระบุจำนวนเงินและสกุลเงินที่ต้องการชำระ
//Amount Object
$amountIns = new Amount();
$amountIns->setTotal(20)->setCurrency('USD'); //must give a valid currency code and must exist in merchant wallet list
It’s a Transaction resource where amount object has to set.
//Transaction Object
$trans = new Transaction();
$trans->setAmount($amountIns);
ตั้งค่า URL ที่ผู้ซื้อจะถูกนำทางหลังธุรกรรมเสร็จหรือยกเลิก
//RedirectUrls Object
$urls = new RedirectUrls();
$urls->setSuccessUrl('http://your-merchant-domain.com/example-success.php') //success url - the merchant domain page, to redirect after successful payment, see sample example-success.php file in sdk root, example - http://techvill.net/PayMoney_sdk/example-success.php
->setCancelUrl('http://your-merchant-domain.com/');//cancel url - the merchant domain page, to redirect after cancellation of payment, example - http://techvill.net/PayMoney_sdk/
It’s a payment resource where all Payer, Amount, RedirectUrls and Credentials of merchant (Client ID and Client Secret) have to set. After initialized into payment object, need to call create method. It will generate a redirect URL. Users have to redirect into this URL to complete the transaction.
//Payment Object
$payment = new Payment();
$payment->setCredentials([ //client id & client secret, see merchants->setting(gear icon)
'client_id' => 'place your client id here', //must provide correct client id of an express merchant
'client_secret' => 'place your client secret here' //must provide correct client secret of an express merchant
])->setRedirectUrls($urls)
->setPayer($payer)
->setTransaction($trans);
try {
$payment->create(); //create payment
header("Location: ".$payment->getApprovedUrl()); //checkout url
} catch (Exception $ex) {
print $ex;
exit; }
จากนั้นไปที่ php-sdk/src/PayMoney/Rest/Connection.php, แล้วเปลี่ยน BASE_URL value to your domain name(i.e: If the domain is - 'your-domain.com' then, define( 'BASE_URL' , 'http://your-domain.com/' ) )
ตัวอย่างโค้ด
require 'vendor/autoload.php';
//if you want to change the namespace/path from 'PayMoney' - lines[1-5] -
//to your desired name, i.e. (use PayMoney\Api\Amount;
//to use MyDomain\Api\Amount;), then you must change the folders name that holds the API classes
//as well as change the property 'PayMoney' in (autoload->psr-0) of (php-sdk/composer.json) file to your
//desired name and run "composer dump-autoload" command from sdk root
use PayMoney\Api\Payer;
use PayMoney\Api\Amount;
use PayMoney\Api\Transaction;
use PayMoney\Api\RedirectUrls;
use PayMoney\Api\Payment;
//Payer Object
$payer = new Payer();
$payer->setPaymentMethod('PayMoney'); //preferably, your system name, example - PayMoney
//Amount Object
$amountIns = new Amount();
$amountIns->setTotal(20)->setCurrency('USD'); //must give a valid currency code and must exist in merchant wallet list
//Transaction Object
$trans = new Transaction();
$trans->setAmount($amountIns);
If you don't see changes after configuring and extracting SDK, go to your SDK root and run the commands below:-