ferdhika31/ipaymu-php

适用于iPaymu API的PHP客户端

0.2 2020-11-27 07:40 UTC

This package is auto-updated.

Last update: 2024-09-29 05:56:07 UTC


README

使用PHP编写的iPaymu API包装器,适用于从应用程序访问。

Build Status StyleCI Coverage Status Latest Stable Version Total Downloads Latest Unstable Version License

文档

有关API文档,请查看iPaymu API文档

安装

使用以下命令通过composer安装此包:

composer require ferdhika31/ipaymu-php

用法

初始化

使用从iPaymu仪表板获得的账户密钥配置包。您可以使用生产环境沙盒环境

<?php
use ferdhika31\iPaymuPHP\iPaymu;

$config = [
    'env'               => 'SANDBOX', // SANDBOX or PRODUCTION
    'virtual_account'   => 'your_virtual_account',
    'api_key'           => 'your_api_key',
    'notify_uri'        => 'https://:8000/notify',
    // for redirect payment is required
    'cancel_uri'        => 'https://:8000/cancel',
    'return_uri'        => 'https://:8000/return'
];

iPaymu::init($config);

有关更多详细信息,请参阅示例代码

获取余额

<?php
use ferdhika31\iPaymuPHP\Balance;

$getBalance = Balance::getBalance();

设置客户

<?php
$customer = [
    'name' => 'Dika',
    'email' => 'fer@dika.web.id',
    'phone' => '083213123332'
];
iPaymu::setCustomer($customer);

添加产品

<?php
iPaymu::addProduct([
    'name'          => 'Mangga',
    'qty'           => 2,
    'price'         => 2500,
    'description'   => 'Mangga cobian'
]);
iPaymu::addProduct([
    'name'          => 'Jeruk',
    'qty'           => 1,
    'price'         => 1500,
    'description'   => 'Jeruk haseum'
]);

创建重定向支付

<?php
use ferdhika31\iPaymuPHP\PaymentRedirect;

// optional
$payloadTrx = [
    'expired' => 1, // in hours
    'comments' => 'Transaction comment here',
    'referenceId' => 'TRX202008310001'
];

$redirectPayment = PaymentRedirect::create($payloadTrx);

使用支付方式创建重定向支付

<?php
use ferdhika31\iPaymuPHP\PaymentRedirect;

// optional
$payloadTrx = [
    'expired' => 1, // in hours
    'comments' => 'Transaction comment here',
    'referenceId' => 'TRX202008310001'
];

$redirectPayment = PaymentRedirect::mandiriVA()->create($payloadTrx);
$redirectPayment = PaymentRedirect::niagaVA()->create($payloadTrx);
$redirectPayment = PaymentRedirect::BNIVA()->create($payloadTrx);
$redirectPayment = PaymentRedirect::BAGVA()->create($payloadTrx);
$redirectPayment = PaymentRedirect::BCATransfer()->create($payloadTrx);
$redirectPayment = PaymentRedirect::QRIS()->create($payloadTrx);
$redirectPayment = PaymentRedirect::CStore()->create($payloadTrx);
$redirectPayment = PaymentRedirect::creditCard()->create($payloadTrx);
$redirectPayment = PaymentRedirect::COD()->create($payloadTrx);
$redirectPayment = PaymentRedirect::akulaku()->create($payloadTrx);

创建直接支付

<?php
use ferdhika31\iPaymuPHP\PaymentDirect;

$payloadTrx = [
    'amount' => 5000,
    // optional
    'expired' => 10,
    'expiredType' => 'minutes', // in:seconds,minutes,hours,days
    'comments' => 'Transaction comment here',
    'referenceId' => 'TRX202008310001'
];

// Available channel Virtual Account : bag, bni, cimb (default), mandiri
$channel = 'mandiri';
$directPayment = PaymentDirect::VA($channel)->create($payloadTrx);

// Available channel Transfer Bank : bca (default)
$channel = 'bca';
$directPayment = PaymentDirect::bankTransfer($channel)->create($payloadTrx);

// Available channel Convenience Store : indomaret (default), alfamart
$channel = 'alfamart';
$directPayment = PaymentDirect::cStore($channel)->create($payloadTrx);

// Available channel: linkaja (default)
$channel = 'linkaja';
$directPayment = PaymentDirect::QRIS($channel)->create($payloadTrx);

获取交易详情

<?php
use ferdhika31\iPaymuPHP\Transaction;

$id = 27958;
$getTrx = Transaction::getById($id);

运行

运行测试套件

vendor\bin\phpunit tests
vendor\bin\phpunit tests\BalanceTest.php

运行示例

php examples\CheckBalanceExample.php

贡献

对于任何请求、错误或评论,请打开问题提交拉取请求