propa / beanstream
Beanstream PHP API
v1.0
2017-10-26 02:53 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-23 14:18:27 UTC
README
Beanstream API的Composer ready PHP包装器。[链接](http://developer.beanstream.com/documentation/)
安装
安装库的推荐方式是使用Composer。
{
"require": {
"propa/beanstream": "~1"
}
}
处理异常
如果服务器返回了意外的响应或错误,PHP API会抛出\Beanstream\Exception。正的错误代码对应Beanstream API错误,参见取款错误,分析支付错误,标记支付错误。负的错误代码对应cURL错误(原始cURL错误代码是正的,在\Beanstream\Exception中这些是相反的)。零错误代码的异常是PHP API特定的,例如需要curl扩展或意外的响应格式。
通常,任何不成功的请求,例如数据不足或交易被拒绝,都会导致抛出\Beanstream\Exception,因此推荐使用try..catch来拦截和处理它们,下面有示例。
您的第一个集成
下面的示例与Beanstream的原始示例等效。
<?php $bm = new \Beanstream\Messenger(YOUR_MERCHANT_ID, YOUR_API_KEY); try { $ts = $bm->payment(array( 'order_number' => '100001234', 'amount' => 100.00, 'payment_method' => 'card', 'card' => array( 'name' => 'John Doe', 'number' => '5100000010001004', 'expiry_month' => '02', 'expiry_year' => '17', 'cvd' => '123' ) )); /* * Handle successful transaction, payment method returns * transaction details as result, so $ts contains that data * in the form of associative array. */ } catch (\Beanstream\Exception $e) { /* * Handle transaction error, $e->code can be checked for a * specific error, e.g. 211 corresponds to transaction being * DECLINED, 314 - to missing or invalid payment information * etc. */ }
提示
身份验证
Beansteam为支付、配置文件和搜索请求定义了不同的API访问密钥。尽管如此,仍然可以使用相同的值,因此可以为每种请求类型初始化单独的\Beanstream\Messanger实例,或者配置Beansteam商户面板中的API密码相同,参见生成API密钥。
账单地址省份
Beanstream要求在提交账单数据时,与province字段一起提交的是两位字母代码。只有当指定的country是US或CA时才需要它,对于其他国家代码,即使相应的国家有州或省,也将其设置为--。