BKM Express เป็นระบบการชำระเงินที่ง่ายและรวดเร็วในตุรกีซึ่งให้การชำระเงินออนไลน์ที่เป็นไปได้โดยไม่ต้องให้ข้อมูลบัตรเครดิตทั้งหมดดังนั้นห้องสมุดนี้ให้ API ง่ายๆ
###### หมายเหตุ: กำลังทำงานในโครงการนี้ เอกสารยังไม่เสร็จสมบูรณ์
คุณสามารถติดตั้งไลบรารีนี้ผ่านนักแต่งเพลง
ประการแรกเพิ่มบรรทัดนี้ลงใน composer.json ของคุณ json
{
"require" : {
"travijuu/bkm-express" : " 1.0.3 "
}
} จากนั้นเรียกใช้คำสั่ง composer update
มีสี่ขั้นตอนในการทำธุรกรรมการชำระเงิน
เริ่มต้นด้วยขั้นตอนแรก
use Travijuu BkmExpress BkmExpress ;
use Travijuu BkmExpress Common Bank ;
use Travijuu BkmExpress Common Bin ;
use Travijuu BkmExpress Common Installment ;
$ mid = ' 7b928290-b6d2-469e-ac10-29eb36b8c1f6 ' ; // BKM Merchant ID
$ successUrl = ' https://example.com/bkm/success ' ;
$ cancelUrl = ' https://example.com/bkm/error ' ;
$ privateKeyPath = ' /path/to/mykey.pem ' ;
$ publicKeyPath = ' /path/to/mykey.pub ' ;
$ bkmPublicKeyPath = ' /path/to/bkm.pub ' ;
// Infrastructure of the bank you choose as a default payment gateway.
// ['Posnet', 'NestPay', 'Gvp'] one of them should be chosen.
$ defaultBank = ' NestPay ' ;
$ bkm = new BkmExpress ( $ mid , $ successUrl , $ cancelUrl , $ privateKeyPath , $ publicKeyPath , $ bkmPublicKeyPath , $ defaultBank );
$ wsdl = ' /path/to/BkmExpressPaymentService.wsdl ' ;
$ sAmount = 100.50 ; // Sale Amount
$ cAmount = 4.50 ; // Cargo Amount
$ banks = [];
$ bank = new Bank ( ' 0062 ' , ' Garanti Bank ' , ' Garanti Bank via BKM Express ' );
$ bin = new Bin ( ' 554960 ' );
$ installment = new Installment ( $ cAmount , $ sAmount , 1 , ' Garanti Bank without installment ' , true );
$ bin -> addInstallment ( $ installment );
$ installment = new Installment ( $ cAmount , $ sAmount , 3 , ' Garanti Bank with 3 installments ' , true );
$ bin -> addInstallment ( $ installment );
$ bank -> addBin ( $ bin );
$ banks [] = $ bank ;
$ response = $ bkm -> initPayment ( $ wsdl , $ sAmount , $ cAmount , $ banks ); จากนั้นทำคำขอโพสต์เป็น $response->getUrl() ด้วยพารามิเตอร์ 3 ตัวโดยการเปลี่ยนเส้นทางไปยัง BKM Express
[
' t ' => $ response -> getToken (),
' s ' => $ response -> getSignature (),
' ts ' => $ response -> getTimestamp ()
]อีกวิธีหนึ่งของการร้องขอโพสต์ (แต่ไม่ต้องการ)
< form name =" bankexpresspayForm " id =" bankexpresspayForm " action =" <?php echo $response->getUrl(); ?> " method =" POST " >
< input type =" hidden " name =" t " value =" <?php echo $response->getToken(); ?> " >
< input type =" hidden " name =" ts " value =" <?php echo $response->getSignature(); ?> " >
< input type =" hidden " name =" s " value =" <?php echo $response->getTimestamp(); ?> " >
<!-- To support javascript unaware/disabled browsers -->
< noscript >
< center >
Eğer yönlenme olmazsa lütfen tıklayınız. < br >
</ center >
</ noscript >
</ form >
< script type =" text/javascript " >
setTimeout ( function ( ) {
$ ( '#bankexpresspayForm' ) . submit ( ) ;
} , 500 ) ;
</ script >หลังจากขั้นตอนนี้คุณควรถูกนำไปยังเว็บไซต์ BKM Express
เมื่อลูกค้าลงชื่อเข้าใช้ระบบบัตรเครดิตที่มีอยู่จะแสดงรายการ ดังนั้นลูกค้าสามารถเห็นตัวเลือกการผ่อนชำระทั้งหมดที่ส่งในการเริ่มต้นคำขอชำระเงิน
หลังจากการเลือกบัตรเครดิตจะมีการร้องขอรหัสผ่าน SMS จากลูกค้า
ในขั้นตอนถัดไป BKM Express จะส่งคำขอ SOAP ไปยังแอปพลิเคชันของคุณเพื่อรับข้อมูล API ของธนาคารซึ่งเกี่ยวข้องกับบัตรที่เลือกของลูกค้า ( Request Merch Info )
สิ่งสำคัญ: คุณควรประกาศ URL Webservice ให้กับ BKM Express Service
ดังนั้น BKM Express จะทำการร้องขอ SOAP ไปยัง URL นี้เพื่อรับข้อมูล API Bank จากเซิร์ฟเวอร์ของคุณ
use Travijuu BkmExpress Common VirtualPos ;
use Travijuu BkmExpress Payment RequestMerchInfo RequestMerchInfoWSRequest ;
$ wsdlServer = ' /path/to/RequestMerchInfoService_latest.wsdl ' ;
$ virtualPosList = [];
$ virtualPos = new VirtualPos ();
$ virtualPos -> setPosUrl ( ' https://sanalposprovtest.garanti.com.tr/VPServlet ' )
-> setPosUid ( ' 600218 ' );
-> setPosPwd ( ' 123qweASD ' );
-> setMpiUrl ( ' https://sanalposprovtest.garanti.com.tr/servlet/gt3dengine ' )
-> setMpiUid ( ' 600218 ' )
-> setMpiPwd ( ' 123qweASD ' )
-> setMd ( '' )
-> setXid ( '' )
-> setCIp ( ' 192.168.0.1 ' )
-> setExtra ( ' {"terminalprovuserid":"PROVAUT", "terminalmerchantid":"7000679", "storekey":"12345678", "terminalid":"30690168"} ' )
-> setIs3ds ( false )
-> setIs3dsFDec ( false );
// Garanti Bank Id: 0062
$ virtualPosList [ ' 0062 ' ] = $ virtualPos ;
/* This callback can help you to be informed what kind of
* payment method is selected in BKM Express website.
* You may insert this into database for info purposes.
* Note: This is optional.
*/
$ callback = function ( RequestMerchInfoWSRequest $ request ) {
$ token = $ response -> getToken ();
$ bankId = $ response -> getBankId ();
$ installment = $ response -> getInstallment ();
. . .
}
$ bkm -> requestMerchInfo ( $ wsdlServer , $ virtualPosList , $ callback ); ผลลัพธ์ของคำขอนี้จะถูกส่งกลับไปยัง BKM Express และจะทำธุรกรรมธนาคารด้วยข้อมูล API ธนาคารของคุณ หลังจากนั้น BKM Express จะทำการร้องขอโพสต์ตามผลของการทำธุรกรรมของธนาคาร ( success / cancel url )
BKM Express จะส่งคำขอโพสต์ไปยัง URL ที่ประสบความสำเร็จ (https://example.com/bkm/success) หรือยกเลิก URL (https://example.com/bkm/error) คุณต้องได้รับข้อมูลโพสต์และส่งผ่านไปยังฟังก์ชั่นยืนยัน
หมายเหตุ: https://example.com/bkm/success/ {orderCode} คุณสามารถใช้ URL ที่ประสบความสำเร็จของคุณเช่นนี้เพื่อช่วยให้คุณเข้าใจว่าคุณพยายามจ่ายเงิน
// This part can be used in both success and cancel url. $confirmation->success() will return the result.
$ data = $ _POST ;
$ confirmation = $ bkm -> confirm ( $ data );
if ( $ confirmation -> isSuccess ()) {
// remember the callback which I decribed above. If you save $token, $bankId, $installment into your database, now you can use them to identify the posResponse.
$ token = $ confirmation -> getToken ();
$ bankId = ' 0062 ' ; // get the bank Id from database according to token
$ posResponse = $ bkm -> getPosResponse ( $ bankId , $ confirmation -> getPosRef ());
// This means that bank transcation is successfully completed so you got the money
// now you can save the success result to your database.
if ( $ posResponse -> isSuccess ()) {
$ authCode = $ posResponse -> getAuthCode ();
$ rawResponse = $ posResponse -> getRawResponse ();
. . .
} else {
// Transaction failed so get the error message and code
$ errorCode = $ posResponse -> getResponseCode ();
$ errorMessage = $ posResponse -> getResponseMessage ();
. . .
}
} นอกเหนือจาก success url BKM Express จะทำการร้องขอโพสต์นี้ไปยัง URL ยืนยันของคุณเพื่อป้องกันไว้ล่วงหน้า พวกเขาสันนิษฐานว่าคำขอที่ส่งไปยัง success url อาจไม่สามารถเข้าถึงได้
สำคัญ: คุณควรประกาศ URL ยืนยันถึง BKM Express Service
$ data = $ _POST ;
$ confirmation = $ bkm -> confirm ( $ data );
/* You can use the same methodology as above.
* Save $token, $bankId, $installment into your database,
* now you can use them to identify the posResponse. (Garanti, YKB, Akbank, etc..)
*/
$ token = $ confirmation -> getToken ();
$ bankId = ' 0062 ' ; // get the bank Id from database according to token
$ posResponse = $ bkm -> getPosResponse ( $ bankId , $ confirmation -> getPosRef ());หากคุณมีข้อเสนอแนะใด ๆ อย่าลังเลที่จะสร้างปัญหาที่นี่เกี่ยวกับ GitHub และ/หรือ Fork repo นี้ทำการเปลี่ยนแปลงและส่งคำขอดึง!