codevirtus/pesepay

Pesepay在线支付集成包

1.0.1 2021-10-22 10:10 UTC

This package is auto-updated.

Last update: 2024-09-22 16:51:30 UTC


README

您可以通过composer安装此包

composer require codevirtus/pesepay

入门指南

将库导入您的项目/应用程序

require_once 'path/to/vendor/autoload.php';
use Codevirtus\Payments\Pesepay

使用由Pesepay提供的集成密钥和加密密钥创建Pesepay类的实例。

$pesepay = new Pesepay("INTEGRATION KEY", "ENCRYPTION KEY");

设置返回和结果URL

$pesepay->returnUrl = "http://example.com/gateway/return";
$pesepay->resultUrl = "http://example.com/gateway/return";

进行无缝支付

创建支付

注意:必须提供客户电子邮件或号码
$payment = $pesepay->createPayment('CURRECNCY_CODE', 'PAYMENT_METHOD_CODE', 'CUSTOMER_EMAIL(OPTIONAL)', 'CUSTOMER_PHONE_NUMBER(OPTIONAL)', 'CUSTOMER_NAME(OPTIONAL)');

创建包含所需字段的object(如果有的话)

$requiredFields = ['requiredFieldName'=>'requiredFieldValue'];

发送支付

$response = $pesepay->makeSeamlessPayment($payment, 'Online Transaction', $AMOUNT, $requiredFields, 'MERCHANT_REFERENCE(OPTIONAL)');

if ($response->success()) {
    # Save the reference number and/or poll url (used to check the status of a transaction)
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();

} else {
    #Get Error Message
    $errorMessage = $response->message();
}

进行重定向支付

创建交易

$transaction = $pesepay->createTransaction($amount, 'CURRENCY_CODE', 'PAYMENT_REASON', 'MERCHANT_REFERENCE(OPTIONAL)');

启动交易

$response = $pesepay->initiateTransaction($transaction);

if ($response->success()) {
    # Save the reference number and/or poll url (used to check the status of a transaction)
    $referenceNumber = $response->referenceNumber();
    $pollUrl = $response->pollUrl();
    # Get the redirect url and redirect user to complete transaction   
    $redirectUrl = $response->redirectUrl();
    
} else {
    # Get error message
    $errorMessage = $response->message();
}

检查支付状态

方法1:使用referenceNumber

$response = $pesepay->checkPayment($referenceNumber);

if ($response->success()) {

    if ($response->paid()) {
        # Payment was successfull
    }

} else {
    # Get error message
    $errorMessage = $response->message();
}

方法2:使用poll URL

$response = $pesepay->pollTransaction($pollUrl);

if ($response->success()) {

    if ($response->paid()) {
        # Payment was successfull
    }

} else {
    # Get error message
    $errorMessage = $response->message();
}