PHP code example of cloudycity / ipaynow-sdk

1. Go to this page and download the library: Download cloudycity/ipaynow-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cloudycity / ipaynow-sdk example snippets


use CloudyCity\IPayNowSDK\IPayNow;
use CloudyCity\IPayNowSDK\Exceptions\Exceptions;
use CloudyCity\IPayNowSDK\Exceptions\InvalidSignException;

$config = [
    'appid' => '123456789012345',                      // 商户应用唯一标识
    'key' => 'abcdefghijklmnopqrstuvwxyz123456789012', // 密钥
    'notify_url' => 'http://cloudycity.me/notify.php', // 异步回调地址 (拉起支付时必选,只用于验证回调时可选)
    'return_url' => 'http://cloudycity.me/return.php', // 同步回调地址 (拉起支付时必选,只用于验证回调时可选)
];

$order = [
    'no' => '1234560', // 订单号
    'money' => 600,    // 订单金额(单位: 分)
    'attach' => '',    // 可选,商户保留域
    'detail' => '',    // 可选,订单详情
    'ip' => '0.0.0.0', // 可选,支付端IP
];

// 拉起支付
try {
    $url = IPayNow::wechat($config)->pre($order);
    $url = IPayNow::ali($config)->pre($order);
} catch (Exceptions $e) {
     //
}

// 校验回调
try {
    PayNow::wechat($config)->verify();
    PayNow::ali($config)->verify();
} catch (InvalidSignException $e) {
    //
}