ipaymu / ipaymu-php-api
iPaymu PHP API 包库
v3.0.4
2023-05-14 19:21 UTC
Requires
- php: >=8.0.0
- ext-curl: *
- phpunit/phpunit: 9.*
Requires (Dev)
- fzaninotto/faker: ^1.9@dev
- mockery/mockery: ^1.2.3
README
官方iPaymu-php-api
这是iPaymu支付API的官方PHP包装库,与Composer兼容。访问https://ipaymu.com获取产品更多信息,并查看https://ipaymu.com/en/api-documentation/以获取更多技术细节。
免费注册https://my.ipaymu.com/members/signup.htm,现在开始在线接受支付!
安装
使用此包的最佳方式是使用composer
composer require ipaymu/ipaymu-php-api
用法
需求
首先,从iPaymu仪表板获取您的apikey和va号码。
初始化
<?php use iPaymu\iPaymu; $apiKey = 'your-apikey'; $va = 'your-va'; $production = true; $iPaymu = new iPaymu($apiKey, $va, $production);
常规
检查余额
$balance = $iPaymu->checkBalance();
检查交易
$status = $iPaymu->checkTransaction($id);
设置URL
$iPaymu->setURL([ 'ureturn' => 'https://your-website/thankyou_page', 'unotify' => 'https://your-website/notify_page', 'ucancel' => 'https://your-website/cancel_page', ]);
设置买家
$buyer = $iPaymu->setBuyer([ 'name' => 'your-name', 'phone' => 'your-phone', 'email' => 'your-email', ]);
支付
有两种支付方式:直接支付和重定向支付,以下参数
paymentMethod
- va => 虚拟账户
- banktransfer => 银行转账
- cstore => 便利店
- cod => 货到付款
- qris => QRIS
paymentChannel
va
- bag => Bank Artha Graha
- bca => Bank Central ASIA
- bni => Bank Negara Indonesia
- cimb => Bank Cimb Niaga
- mandiri => Bank Mandiri
- bmi => Bank Muamalat Indonesia
- bri => Bank Rakyat Indonesia
- bsi => Bank Syariah Indonesia
- permata => Bank Permata
- danamon => Bank Danamon
cstore
- indomaret
- alfamart
cod
- rpx
qris
- qris
参数
将产品添加到购物车
首先,请在使用此方法之前先将产品添加到购物车中
$carts = []; $carts = $iPaymu->add( 'PROD0001', // product id (string) 'Jacket', // product name (string) 12000, // price (float) 2, // quantity (int) 'Size M', // description 1, // product weight (int) (optional) 1, // product length (int) (optional) 1, // product weight (int) (optional) 1 // product height (int) (optional) ); $carts = $iPaymu->add( 'PROD0002', // product id (string) 'Shoe', // product name (string) 150000, // price (float) 2, // quantity (int) 'Size 8', // description 1, // product weight (int) (optional) 1, // product length (int) (optional) 1, // product weight (int) (optional) 1 // product height (int) (optional) ); $iPaymu->addCart($carts);
设置COD(仅限COD方式)
$delivery = $iPaymu->setCOD([ 'deliveryArea' => "76111", 'deliveryAddress' => "Denpasar", ]);
设置过期时间(自定义过期时间)
// set your expiredPayment $iPaymu->setExpired(24, 'hours'); // 24 hours
设置参考ID(可选)
$iPaymu->setReferenceId('123123');
设置支付备注(可选)
$iPaymu->setComments('Payment TRX01');
直接支付
直接支付方法允许您在结账页面上直接接受支付,此方法适用于除信用卡以外的任何支付渠道。
设置支付方法和支付渠道
// set payment method // check https://ipaymu.com/api-collection for list payment method $iPaymu->setPaymentMethod('va'); // check https://ipaymu.com/api-collection for list payment channel $iPaymu->setPaymentChannel('bca');
$payment = $iPaymu->directPayment();
重定向支付
为了接受信用卡,您必须使用重定向支付方法。结账时,您将被重定向到iPaymu.com支付页面以进行进一步的支付处理。
$payment = $iPaymu->redirectPayment();
完整代码示例
直接支付示例
$apiKey = 'QbGcoO0Qds9sQFDmY0MWg1Tq.xtuh1'; // your api key $va = '1179000899'; // your va $production = true; // set false to sandbox mode $iPaymu = new iPaymu($apiKey, $va, $production); // set callback url $iPaymu->setURL([ 'ureturn' => 'https://your-website/thankyou_page', 'unotify' => 'https://your-website/notify_page', 'ucancel' => 'https://your-website/cancel_page', ]); // set buyer name $iPaymu->setBuyer([ 'name' => 'Bagus', 'phone' => '08123123139', 'email' => 'bagus@gmail.com', ]); // set your reference id (optional) $iPaymu->setReferenceId('123123'); // set your expiredPayment $iPaymu->setExpired(24, 'hours'); // 24 hours // set payment method // check https://ipaymu.com/api-collection for list payment method $iPaymu->setPaymentMethod('va'); // check https://ipaymu.com/api-collection for list payment channel $iPaymu->setPaymentChannel('bca'); // payment notes (optional) $iPaymu->setComments('Payment TRX01'); $carts = []; $carts = $iPaymu->add( 'PROD0001', // product id (string) 'Jacket', // product name (string) 12000, // price (float) 3, // quantity (int) 'Size M', // description 1, // product weight (int) (optional) 1, // product length (int) (optional) 1, // product weight (int) (optional) 1 // product height (int) (optional) ); $carts = $iPaymu->add( 'PROD0002', // product id (string) 'Shoe', // product name (string) 150000, // price (float) 2, // quantity (int) 'Size 8', // description 1, // product weight (int) (optional) 1, // product length (int) (optional) 1, // product weight (int) (optional) 1 // product height (int) (optional) ); $iPaymu->addCart($carts); return $iPaymu->directPayment();
重定向支付示例
$apiKey = 'QbGcoO0Qds9sQFDmY0MWg1Tq.xtuh1'; // your api key $va = '1179000899'; // your va $production = true; // set false to sandbox mode $iPaymu = new iPaymu($apiKey, $va, $production); // set callback url $iPaymu->setURL([ 'ureturn' => 'https://your-website/thankyou_page', 'unotify' => 'https://your-website/notify_page', 'ucancel' => 'https://your-website/cancel_page', ]); // set buyer name $iPaymu->setBuyer([ 'name' => 'Bagus', 'phone' => '08123123139', 'email' => 'bagus@gmail.com', ]); // set your reference id (optional) $iPaymu->setReferenceId('123123'); // set your expiredPayment $iPaymu->setExpired(24, 'hours'); // 24 hours // set cod param (optional) $iPaymu->setCOD([ 'deliveryArea' => "76111", 'deliveryAddress' => "Denpasar", ]); $carts = []; $carts = $iPaymu->add( 'PROD0001', // product id (string) 'Jacket', // product name (string) 12000, // price (float) 2, // quantity (int) 'Size M', // description 1, // product weight (int) (optional) 1, // product length (int) (optional) 1, // product weight (int) (optional) 1 // product height (int) (optional) ); $carts = $iPaymu->add( 'PROD0002', // product id (string) 'Shoe', // product name (string) 150000, // price (float) 2, // quantity (int) 'Size 8', // description 1, // product weight (int) (optional) 1, // product length (int) (optional) 1, // product weight (int) (optional) 1 // product height (int) (optional) ); $iPaymu->addCart($carts); return $iPaymu->redirectPayment();