我正在为 friend 开发一个电子商务网站,并且在执行付款之前用运费更新 Paypal,我收到以下错误。当我调用 Patch、PatchRequest,然后尝试执行支付时,会发生此错误。以下是所有代码:
if (Input::get('action', 'get') === "getDetails") { //Check to see if the action parameter is set to getDetails
$payment = \PayPal\Api\Payment::get(Input::get('paymentId', 'get'), $paypalAPI);
$payerInfo = $payment->getPayer()->payer_info;
if (!empty($payment)){
$quantity = 0;
foreach ($payment->transactions[0]->item_list->items as $item) {
$quantity += $item->quantity;
}
if ($quantity <= 20) {
$parcelType = "MediumFlatRateBox";
} else if ($quantity > 20) {
$parcelType = "LargeFlatRateBox";
}
$shipment = \EasyPost\Shipment::create([
'from_address' => \EasyPost\Address::retrieve(Config::get('easypost/addressObjectID')),
'to_address' => [
'name' => $payerInfo->shipping_address->recipient_name,
'street1'=> $payerInfo->shipping_address->line1,
'street2' => (isset($payerInfo->shipping_address->line2)) ? $payerInfo->shipping_address->line2 : null,
'city' =>$payerInfo->shipping_address->city,
'state' => $payerInfo->shipping_address->state,
'country' => $payerInfo->shipping_address->country_code,
'zip' => $payerInfo->shipping_address->postal_code,
'email' => $payerInfo->email
],
'parcel' => [
'predefined_package' => $parcelType,
'weight' => 520
]
]);
//Grab the lowest shipping rate
$shippingRate = $shipment->lowest_rate()->rate;
//Make a call to PayPal updating our transaction with the tax and shipping rate
$amount = $payment->transactions[0]->amount;
$transactionUpdate = new \PayPal\Api\Patch();
$transactionUpdate ->setOp('replace')
->setPath('transactions/0/amount')
->setValue(json_decode('{
"total": "'.$amount->total.'",
"currency":"USD",
"detail": {
"subtotal": "'.$amount->details->subtotal.'",
"shipping":"'.$shippingRate.'"
}
}'));
//Instantiate a new instance of PayPal's Patch Request Class and Update the Transaction with the tax and shipping rate
$updateRequest = new \PayPal\Api\PatchRequest();
$updateRequest->setPatches(
[$transactionUpdate]
);
//Attempt Update
$result = $payment->update($updateRequest, $paypalAPI);
if ($result) {
$transID = generateTransactionID();
$fields = [
'dateCreated' => strtotime($payment->create_time),
'transID' => $transID,
'paymentID' => $payment->id,
'shipmentID' => $shipment->id
];
$db->insert('transactionLog', $fields);
Redirect::to('shoppingCartFinalize.php?transID='.$transID);
exit();
} else {
Alert::set([
'header' => "Uh Oh....Something Went Wrong",
'message' => "Unable to update transaction. Transaction Cancelled. Please try again.",
'type' => 'danger',
'close' => 1
]);
Redirect::to('shoppingCartView.php');
exit();
}
}
以下是我在通话过程中遇到的错误:
Fatal error: Uncaught exception 'PayPal\Exception\PayPalConnectionException' with message 'Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment/PAY-77N347011V970714EKU2D24Q.' in /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:177 Stack trace: #0 /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Transport/PayPalRestCall.php(74): PayPal\Core\PayPalHttpConnection->execute('[{"op":"replace...') #1 /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Common/PayPalResourceModel.php(103): PayPal\Transport\PayPalRestCall->execute(Array, '/v1/payments/pa...', 'PATCH', '[{"op":"replace...', NULL) #2 /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Api/Payment.php(474): PayPal\Common\PayPalResourceModel::executeCall('/v1/payments/pa...', 'PATCH', '[{"op":"replace...', NULL, Object(PayPal\Rest\ApiContext), NULL) #3 /var/www/html/myla-dev/apiProcessing.php(146): PayPal\Api\Payment->update(Object(PayPal\Api\ in /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php on line 177
更新:感谢您对 Thaer 的帮助。它有帮助。现在我收到一个单独的错误。当我尝试更新付款时,它现在显示以下内容:
Array ( [name] => PAYMENT_STATE_INVALID [message] => This request is invalid due to the current state of the payment [information_link] => https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID [debug_id] => 1b1b9b71e91d8 )
如果您知道如何解决这个问题,请。我不知道如何更改状态以便更新付款。
如果您发现错误,请告诉我。我被困住了,这不好笑。
戴夫·道格拉斯
最佳答案
请引用这个Answer 我认为您必须尝试 - 捕获您的代码以确定错误 ,问候。
关于php - 交易更新期间的 Paypal PHP SDK HTTP 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29737400/