cashmos / cashmos-php-api
在线支付处理器
v1.0.1
2019-08-07 20:30 UTC
Requires
- guzzlehttp/guzzle: ^6.2
- illuminate/support: ^5.0
Requires (Dev)
- mockery/mockery: ^0.9.9
- phpunit/phpunit: ^6.2
- dev-master
- v1.0.1
- v1.0.0
- dev-dependabot/npm_and_yarn/json5-1.0.2
- dev-dependabot/npm_and_yarn/flat-and-mocha-5.0.2
- dev-dependabot/npm_and_yarn/decode-uri-component-0.2.2
- dev-dependabot/npm_and_yarn/loader-utils-1.4.2
- dev-dependabot/npm_and_yarn/moment-2.29.4
- dev-dependabot/npm_and_yarn/copy-props-2.0.5
- dev-dependabot/composer/guzzlehttp/guzzle-6.5.8
- dev-dependabot/composer/guzzlehttp/psr7-1.8.5
- dev-dependabot/npm_and_yarn/path-parse-1.0.7
- dev-dependabot/npm_and_yarn/hosted-git-info-2.8.9
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/y18n-3.2.2
- dev-dependabot/npm_and_yarn/ini-1.3.7
This package is auto-updated.
Last update: 2024-09-07 10:14:24 UTC
README
这是Cashmos支付处理的官方PHP SDK。
安装
SDK可以通过composer轻松安装。要安装,请在您的终端或Windows上的命令提示符中运行以下命令(确保composer已安装并在您的项目目录中可用)。
composer require cashmos/cashmos-php-api
如果您不想使用composer,您可以直接从版本中下载zip文件。
身份验证与Cashmos服务
要使用此SDK提供的任何服务,您将需要您的商业账户的客户端ID
和密钥
。这些可以在Cashmos在线业务屏幕的API选项卡下查看。如果您还没有账户,可以在Cashmos.com创建一个商业账户。
$cashmos = new Cashmos\Cashmos($clientId, $secret);
订单处理
使用以下步骤通过Cashmos处理订单
I. 创建订单
$order = new Cashmos\Services\Order\Order(); // Add items to order $order->addItem( new Cashmos\Services\Order\Item($name, $unitPrice, $quantity, $description), ); $order->addItem( new Cashmos\Services\Order\Item($name2, $unitPrice2, $quantity2, $description2), ); // Set order total. // Note that this is the total amount to be charged to the user. // Cashmos does not do any item level calculations for total amount. $order->setOrderTotal($orderTotal) // You can add any custom data to the order which // could be retrieved later after confirmation. // This may be information used to identify the customer // making the order, etc. $customData = [ 'foo' => 'bar' ]; $order->addCustomData($customData); // Set return and cancel urls $order->returnUrl('https://business.com/paid'); // Url when payment authorization was successful. $order->cancelUrl('https://business.com/canceled'); // Url when payment authorization was canceled.
II. 处理订单授权
此步骤允许用户选择他们的支付方式并提供购买授权。然而,用户的账户实际上并未被扣款。使用下一个步骤来确认订单并实际扣款。
$cashmos = new Cashmos\Cashmos($clientId, $secret); $cashmos->process($order);
如果用户授权支付,Cashmos会带着支付令牌(作为查询参数?token="random-token")返回到提供的"returnUrl"。此支付令牌用于确认支付。
III. 确认订单
$confirmation = new Cashmos\Services\Order\OrderConfirmation($token); $cashmos = new Cashmos\Cashmos($clientId, $secret); if($cashmos->process($confirmation)){ // Order confirmed successfully. // You can get any custom data after the order is confirmed. $customData = $confirmation->getCustomData(); }else{ // There was an error with order confirmation echo $cashmos->getError(); }
先决条件
安全漏洞
如果您在此API中发现安全漏洞,请将漏洞详情通过电子邮件发送至technical@omnile.com。