此付款请求必须由发件人 - PayPal 授权



好的,这是我所做的:

  1. 已创建付款请求

  2. 设置付款选项 - https://developer.paypal.com/webapps/developer/docs/classic/api/adaptive-payments/SetPaymentOptions_API_Operation/

  3. 执行付款 - "此付款请求必须由发件人授权"。我已经不知道为什么我无法执行付款。据我了解,一旦我成功执行付款,我将获得一个 payKey,我将使用它将用户重定向到PayPal。https://developer.paypal.com/webapps/developer/docs/classic/api/adaptive-payments/ExecutePayment_API_Operation/

附上我使用的源代码。这些值都是硬编码的。我已经尽力研究类似的问题,这对我来说毫无意义,因为它与我的理解相矛盾。一些答案指出,在您执行付款之前,买方需要先批准付款。

我只想在到达PayPal登录页面时查看所有项目的详细信息。

//1. Obtain endpoint. For live, no need sandbox?
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/Pay";
//2. Format the HTTP headers needed to make the call.
$appID = "xxx"; //Sandbox test AppID:
$username = "xxx;
$password = "xxx";
$signature = "xxx";
$paypalHeaders = array(
    "X-PAYPAL-SECURITY-USERID :" . $username,
    "X-PAYPAL-SECURITY-PASSWORD :" . $password,
    "X-PAYPAL-SECURITY-SIGNATURE :" . $signature,
    "X-PAYPAL-APPLICATION-ID :" . $appID,
    "X-PAYPAL-REQUEST-DATA-FORMAT : JSON",
    "X-PAYPAL-RESPONSE-DATA-FORMAT : JSON"
);

$data = array();
$data['actionType'] = "CREATE"; //PAY
$data['currencyCode'] = "SGD";
$receiver['amount'] = $orderTotal;
$receiver['email'] = $receiverEmail;
$data['receiverList'] = array();
$data['receiverList']['receiver'][] = $receiver;
$data['returnUrl'] = $returnURL;
$data['cancelUrl'] = $cancleURL;
$requestEnvelope = array();
$requestEnvelope['errorLanguage'] = "en_US";
$data['requestEnvelope'] = $requestEnvelope;
//I omitted the POST call
//print_r($returnedData);
$payKey = $returnedData->payKey;  
$paymentStatus = $returnedData->paymentExecStatus;

/* *设置付款方式 */

$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/SetPaymentOptions";
//paymentDetailsData
$paymentDetailsData = array();
//set payKey
echo "payKey: " . $payKey;
$paymentDetailsData['payKey'] = $payKey;
//displayOptions
$displayOptions['businessName'] = "My Business";
$paymentDetailsData['displayOptions'] = $displayOptions;
//senderOptions
$senderOptions = array();
$senderOptions['requireShippingAddressSelection'] =  true; //set to true if courier is chosen
$senderOptions['shippingAddress']['addresseeName'] = "Ny Name";
$senderOptions['shippingAddress']['street1'] = "Address 1Avenue 3";
$senderOptions['shippingAddress']['street2'] = "#xx-112";
$senderOptions['shippingAddress']['city'] = "Singapore";
$senderOptions['shippingAddress']['state'] = "Singapore";
$senderOptions['shippingAddress']['zip'] = "123456";
$senderOptions['shippingAddress']['country'] = "Singapore";
$paymentDetailsData['senderOptions'] = $senderOptions;
//item
$item = array();
$item['name'] = "Korea";
$item['itemPrice'] = 11;
//there is still price, and itemcount
//invoiceData
$invoiceData = array();
$invoiceData['item'] = $item;
//receiverOptions
$receiverOptions = array();
$receiverOptions['description'] = "Product description.";
$receiverOptions['invoiceData'] = $invoiceData;
$paypalEmail = "test@test.com"; //I may need to change this
$receiver['email'] = $paypalEmail;
$receiverOptions['receiver'] = $receiver;
$paymentDetailsData['receiverOptions'] = $receiverOptions;
//requestEnvelope. I have set the request envelope above. It is the same. Can still be used.
$paymentDetailsData['requestEnvelope'] = $requestEnvelope;
makePaypalCall($endPoint, $paypalHeaders, $paymentDetailsData);
/*
 * Get payment options. I can see the result of get payment options correctly,
 */
echo "GETTING PAYMENT OPTIONS";
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/GetPaymentOptions";
$getPaymentData['payKey'] = $payKey;
$getPaymentData['requestEnvelope'] = $requestEnvelope;
makePaypalCall($endPoint, $paypalHeaders, $getPaymentData);
$endPoint = "https://svcs.sandbox.paypal.com/AdaptivePayments/ExecutePayment";

/*
 * ExecutePayment. Ok, I get the error here. This payment request must be authorized by the sender
 */
$executePaymentData = array();
echo "paykey: " . $payKey;
$executePaymentData['payKey'] = $payKey;
//$executePaymentData['actionType'] = "PAY";
$executePaymentData['requestEnvelope'] = $requestEnvelope;

我希望我理解正确。

对我来说,您似乎跳过了用户需要授权付款的步骤。执行付费(创建)操作时,应会看到PayPal响应中获取重定向URL。您需要将用户重定向到此 URL,以便他们授权PayPal付款。

一旦他们批准了付款,您就可以执行付款了。

您的步骤需要更改为:

  1. 创建付款请求
  2. 设置付款选项
  3. 重定向至PayPal(来自PayRequest响应的重定向URL)进行用户授权
  4. 如果获得授权,执行付款

PayPal Pay API 操作页面上对此的提示

URL to redirect the sender's browser to after the sender has logged into PayPal and approved a payment; it is always required but only used if a payment requires explicit approval

在步骤 3 之后,用户将返回到您在 $data['returnUrl'] = $returnURL; 中提供的 URL

我正在使用延迟链式付款,并且经常出现此错误"此付款请求必须由发件人授权"。实际上,这是由于逻辑上的一个小错误。

错误的程序(@步骤3)

  1. 成功生成支付密钥
  2. 将其保存到数据库
  3. 由于某种原因刷新页面,导致生成新的 payKey(这个新的 payKey 不会更新到数据库)

    payRequest = pay();
    .....
    if(empty(db_record)) {
      .....
      db_record->payKey = payRequest->payKey;
      db_record->save();
    }
    
  4. 使用新的支付密钥付款(即发件人批准的付款)

  5. 尝试使用数据库中的 payKey 执行付款(这确实是旧的。该支付密钥未用于付款)

溶液

使用上次付款密钥更新数据库,该数据库用于通过获得发件人的批准进行付款

第 3 步应该像

    if(empty(db_record) || is_expired(db_record->payKey)) {
      payRequest = pay();
      .....
      .....
      db_record->payKey = payRequest->payKey;
      db_record->save();
    }

最新更新