Kamlesh Kumar
Kamlesh Kumar

Reputation: 21

Afterpay payment gateway response issue

I am integrating afterpay payment gateway by the help of https://developers.afterpay.com/afterpay-online/reference#create-checkout-1 this page. I added all required parms in curl header. but i am getting error in curl response. I searched alot but didnt got any solution, please suggest any tutorial that works properly or give any solution. here is my curl code

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));  
}

and i am getting this in response

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

Thanks.

Upvotes: 0

Views: 546

Answers (1)

user16308749
user16308749

Reputation: 11

This resource from Afterpay's public Github repo may be useful: https://github.com/afterpay/sdk-php#troubleshooting

The first thing to try is – Pass the raw values into the amount object. This applies for amount, taxAmount, and shippingAmount eg)

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

I also noticed a misspelling in the redirectCancelURL, I believe the path should be: https://localhost/beuaty/public/cart'

Upvotes: 1

Related Questions