asiabill/asiabill_php_sdk

快速访问asiabill支付PHP SDK

v1.5 2022-08-22 08:17 UTC

This package is auto-updated.

Last update: 2024-09-22 12:25:12 UTC


README

这是一个集成了AsiaBill的支付和openApi接口的组件,通过传递指定请求类型和对应的参数即可完成接口请求。使用前请先阅读Asiabill接口文档

支付演示页面访问:asiabill_php_sdk/demo/checkout.php

PHP要求

使用PHP SDK

1、加载AsiabillIntegration.php文件

include_once "Classes/AsiabillIntegration.php"; 

2、初始化对象

use \Asiabill\Classes\AsiabillIntegration;
$model = 'test'; // test or live
$asiabill = new AsiabillIntegration($model,$gateway_no,$sign_key);

3、开启日志,可以通过参数设置目录,如果不开启则跳过这一步

$asiabill->startLogger($bool,$dir);

4、发起payment请求

$asiabill->request($type,$data);
$asiabill->payment()->request($type,$data);

5、发起openapi请求

$asiabill->openapi()->request($type,$data);

6、获取站内支付jssdk脚本

$asiabill->getJsScript();

参数说明

type:请求类型:自定义字符串
data:请求参数:数组参数,包含path,body,query三个部分

示例代码

创建交易:

$result = $asiabill->request('checkoutPayment',['body' => [
    'billingAddress' => [
        'address' => 'address',
        'city' => 'BR',
        'country' => 'country',
        'email' => '123451234@email.com',
        'firstName' => 'firstName',
        'lastName' => 'lastName',
        'phone' => '13800138000',
        'state' => 'CE',
        'zip' => '666666'
    ],
    'callbackUrl' => $http_type.'://'.$_SERVER['HTTP_HOST'].'/Asiabill/return.php',
    'customerId' => '', // asiabill创建的客户id,非网站用户id
    'deliveryAddress' => [
        'shipAddress' => 'mfdgohmqkpocemkqwtks',
        'shipCity' => 'MQOHUPOX',
        'shipCountry' => 'BR',
        'shipFirstName' =>  'SFDMPG',
        'shipLastName' =>  'USJAXT',
        'shipPhone' => '62519594707',
        'shipState' => 'WEWBZ',
        'shipZip' => '512008'
    ],
    'goodsDetails' => [
        [
            'goodsCount' => '1',
            'goodsPrice' => '6.00',
            'goodsTitle' => 'goods_1'
        ]
    ],
    'isMobile' => $asiabill->isMobile(), // 0:web, 1:h5, 2:app_SDK
    'orderAmount' => '7.00',
    'orderCurrency' => 'USD',
    'orderNo' => getOrderNo(),
    'paymentMethod' => 'Credit Card', // 其它支付方式请参考文档说明
    'platform' => 'php_SDK', // 平台标识,用户自定义
    'remark' => '', // 订单备注信息
    'returnUrl' => $http_type.'://'.$_SERVER['HTTP_HOST'].'/Asiabill/return.php',
    'webSite' => $_SERVER['HTTP_HOST']
]]);

if($result['code'] == '0000'){
    /* Your business code */
}

查询交易信息:

$asiabill->openapi()->request('orderInfo',['path' => [
    'tradeNo' => $tradeNo
]]);

创建客户:

$asiabill->request('customers',['body' => [
    'description' => 'test customer',
    'email' => '123451234@email.com',
    'firstName' => 'firstName',
    'lastName' => 'lastName',
    'phone' => '13800138000'
]]);

删除客户:

$asiabill->request('customers',['path' => [
    'customerId' => $customer_id
],'delete' => true]);

签名校验

$asiabill->verification()

获取webhook数据

$asiabill->getWebhookData();

payment类型

openApi类型

添加自定义类型

  • $request_type 请求类型,自定义字符,与request第一个参数一致,已经存在的类型不能添加
  • $request_path 接口路径,参考asiabill接口文档
$asiabill->addRequest($request_type,$request_path)->request($request_type,$data);
$asiabill->addRequest($request_type,$request_path)->openapi()->request($request_type,$data);