cashmos/cashmos-php-api

在线支付处理器


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

许可证