首页 > 解决方案 > Afterpay支付网关响应问题

问题描述

我在 https://developers.afterpay.com/afterpay-online/reference#create-checkout-1这个页面的帮助下集成了 afterpay 支付网关。我在 curl 标头中添加了所有必需的参数。但我在卷曲响应中遇到错误。我搜索了很多但没有得到任何解决方案,请建议任何正常工作的教程或提供任何解决方案。这是我的卷曲代码

private function requestCurl($data){
    $array = array(
      'amount' => [
          'amount' => number_format((float)$data['amount'], 2, '.', ''),
          'currency' => 'USD'
      ],
      'consumer' => [
          'givenNames' => $data['first_name'],
          'surname' =>  $data['last_name'],
          'email' => $data['email']
      ],
      'billing' => [
          'name' => $data['first_name'] . ' '. $data['last_name'],
          'line1' => $data['address'],
          "area1" => "San Francisco",
          "region"=> "CA",
          "countryCode"=> "US",
          'postcode' => $data['zip_code']
      ],
      'shipping' => [
          'name' => $data['first_name'] . ' '. $data['last_name'],
          'line1' => $data['address'],
          "area1" => "San Francisco",
          "region"=> "CA",
          "countryCode"=> "US",
          'postcode' => $data['zip_code']
      ],
      'merchant' => [
          'redirectConfirmUrl' => 'https://localhost/beauty/public/checkout/success',
          'redirectCancelUrl' => 'https://localhost/beuty/public/cart'
      ],
      'taxAmount' => [
          'amount' => 0.00,
          'currency' => 'USD'
      ],
      'shippingAmount' => [
          'amount' => 5.00,
          'currency' => 'USD'
      ]
    );

  


    $_h = curl_init();
    curl_setopt_array($_h, [
        CURLOPT_URL => "https://api.us-sandbox.afterpay.com/v2/checkouts",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_ENCODING => "",
        CURLOPT_MAXREDIRS => 10,
        CURLOPT_TIMEOUT => 30,
        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
        CURLOPT_CUSTOMREQUEST => "POST",
        CURLOPT_POSTFIELDS => json_encode($array),
        CURLOPT_HTTPHEADER => [
            "Accept: application/json",
            "Authorization: Basic MYID",
            "Content-Type: application/json",
            "User-Agent: Readme.io API Simulator"
        ],
    ]);



    echo "<pre>", print_r(curl_exec($_h));  
}

我得到了这个回应

 {
  "errorCode" : "error",
  "errorId" : "f91a4cc29d926c20",
  "message" : "An error occurred processing your request",
  "httpStatusCode" : 500
}

谢谢。

标签: phpcurlpayment

解决方案


Afterpay 的公共 Github 存储库中的此资源可能有用: https ://github.com/afterpay/sdk-php#troubleshooting

首先要尝试的是——将原始值传递给amount对象。这适用于amount,taxAmountshippingAmount eg)

'amount' =>[ number_format((float)$data['amount'], 2, '.', '') , 'USD']

我还注意到 中的拼写错误redirectCancelURL,我相信路径应该是:https://localhost/beuaty/public/cart'


推荐阅读