placetopay/bancolombia-sdk

连接Bancolombia API的库

1.0.0 2021-10-11 17:04 UTC

This package is auto-updated.

Last update: 2024-09-11 23:48:56 UTC


README

允许连接Bancolombia提供的支付按钮

文档 https://developer.bancolombia.com/en/node/3252

安装

composer require placetopay/bancolombia-sdk

使用

创建库的实例

提供流程的配置设置,您可以在应用的页面找到客户端ID https://developer.bancolombia.com/en/application,但密钥只有在应用创建后才会显示,之后将无法再次获取。

哈希是会被转换为commerceTransferButtonId的值。此值将由他们提供

$clientId = 'YOUR APP CLIENT ID';
$clientSecret = 'YOUR APP SECRET';
$hash = 'h4ShG3NER1C';
$bancolombia = \PlacetoPay\BancolombiaSDK\BancolombiaButton::load($clientId, $clientSecret, $hash);

创建新的支付意向

这将返回一个用户应该重定向以完成流程的URL

try {
    $result = $bancolombia->request([
        'reference' => 'YOUR_UNIQUE_REFERENCE',
        'description' => 'SOME TEXT TO DISPLAY',
        'amount' => 32178,
        'returnUrl' => 'URL_IN_WHICH_THE_USER_WILL_RETURN',
        'confirmationUrl' => 'URL_TO_RECEIVE_THE_CALLBACK',
    ]);
    
    // Gives the URL to send the user to
    $result->processUrl();
    // Gives the transfer code that identifies this session on Bancolombia
    $result->code();
    // Gives the id for the transference process
    $result->id();
} catch (\PlacetoPay\BancolombiaSDK\Exceptions\BancolombiaException $e) {
    // Handle the exception
}

处理回调

一旦交易完成,将向之前提供的确认URL发送POST调用,要处理它,您只需将那些数据放入数组,并将其传递给SDK

// Assuming that you dont use any framework
$posted = $_POST;

try {
    $result = \PlacetoPay\BancolombiaSDK\BancolombiaButton::handleCallback($posted, 'THE_SECRET');
    // Handle it the same way that querying it
} catch (\PlacetoPay\BancolombiaSDK\Exceptions\BancolombiaException $e) {
    // Signature failed, do not trust this information
}

查询转账状态

尽管您应该真的依赖回调来了解支付的状态,但此服务也提供了支付的状态

try {
    $result = $bancolombia->query('TRANSFER_CODE');
    if ($result->isApproved()) {
        // Well, they pay you, handle it, also you can use the reference and authorization for example to link the info
        // if you require it
    }
    
    if ($result->isPending()) {
        // They can still pay you
    }
    
    if ($result->isRejected()) {
        // There will be no money, you can try it again
    }
} catch (\PlacetoPay\BancolombiaSDK\Exceptions\BancolombiaException $e) {
    // Handle the exception
}

检查按钮的健康状态

允许检查服务是否正常运行

try {
    $result = $bancolombia->health();
    if ($result->isHealthy()) {
        // All OK
    }
} catch (\PlacetoPay\BancolombiaSDK\Exceptions\BancolombiaException $e) {
    // Handle the exception
}