【发布时间】:2015-06-26 13:25:48
【问题描述】:
我正在为一位朋友开发一个电子商务网站,并在执行付款之前使用运费更新 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();
}
}
以下是我在通话过程中遇到的错误:
致命错误:未捕获的异常 'PayPal\Exception\PayPalConnectionException' 带有消息'Got Http 访问时响应码 400 https://api.sandbox.paypal.com/v1/payments/payment/PAY-77N347011V970714EKU2D24Q.' 在 /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php:177 堆栈跟踪:#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->更新(对象(PayPal\Api\ in /var/www/html/myla-dev/vendor/paypal/rest-api-sdk-php/lib/PayPal/Core/PayPalHttpConnection.php 在第 177 行
更新:感谢 Thaer 的帮助。它有帮助。现在我得到一个单独的错误。当我尝试更新付款时,它现在显示以下内容:
数组 ( [名称] => PAYMENT_STATE_INVALID [message] => 由于当前付款状态,此请求无效 [信息链接] => https://developer.paypal.com/webapps/developer/docs/api/#PAYMENT_STATE_INVALID [debug_id] => 1b1b9b71e91d8)
如果你知道如何解决这个问题,请。我不知道如何更改状态以便更新付款。
如果您发现错误,请告诉我。我被卡住了,这不好笑。
戴夫·道格拉斯
【问题讨论】:
标签: php paypal sdk paypal-rest-sdk