0
我使用快速結賬REST API在Paypal上進行付款。我使用PHP中的CURL成功地檢索了我的令牌。然而,實際上進行付款的下一部分不起作用。PHP | Paypal Rest API | java.lang.NullPointerException
我得到以下錯誤:
顯示java.lang.NullPointerException(我beleive這個錯誤是來自PayPal?)
我曾嘗試通過代碼去,但我不明白我在做什麼因爲它都是簡單的結構。
我的代碼:
$payment_result_json = array(
"intent" => "sale",
"redirect_urls" => array("return_url" => "http://paypal/paypal_return.php", "cancel_url" => "http://paypal/paypal_cancel.php"),
"payer" => array("payment_method" => "paypal"),
"transactions" => array(
"amount" => array("amount" => array(
"total" => "1", "currency" => "USD", "details" => array(
"subtotal" => "1", "shipping" => "0", "tax" => "1", "shipping_discount" => "0"
)
)),
"item_list" => array("quantity" => "1", "name" => "Item 1", "price" => "1", "currency" => "USD", "description" => "item1 desc","tax" => "1"),
"description" => "Tutoring lesson"
));
$post_headers = array("Authorization: Bearer $retreived_access_token");
$ch = curl_init("https://api.sandbox.paypal.com/v1/payments/payment");
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $post_headers);
while(empty($payment_result)){
$payment_result = curl_exec($ch);
}
if(empty($payment_result)){
print curl_error($ch);
}else{
print $payment_result;
}
curl_close($ch);
$payment_result_json = json_decode($payment_result);
print_r($payment_result_json);