我目前正在使用贝宝沙箱中的自定义购物车测试在线商店。我能够正确地完成所有交易步骤 setExpressCheckout-> pay -> DoExpressCheckout。
在 DoExpressCheckout 步骤中,我认为现在是使用订单更新数据库的好时机。为此,我使用 GetExpressCheckoutDetails 函数来检索交易的内容。可悲的是,此功能返回贝宝必须提供的所有内容,但错过了我购物车的内容。我能得到的只是一件物品的细节。如果交易涉及多个项目,我只会得到第一个项目的详细信息。
这是我的代码(主要取自贝宝样本):
$token =urlencode( $_REQUEST['token']);
$payerId=urlencode( $_REQUEST['PayerID']);
$getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($token);
$getExpressCheckoutReq = new GetExpressCheckoutDetailsReq();
$getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest;
$paypalService = new PayPalAPIInterfaceServiceService();
$getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq);
$details = $getECResponse->GetExpressCheckoutDetailsResponseDetails;
// $details->PaymentDetails->PaymentDetailsItem this array should hold all items details
// sadly it always have 1 element instead of the full content of my cart :(
$orderTotal = $details->PaymentDetails->OrderTotal;
$PaymentDetails= new PaymentDetailsType();
$PaymentDetails->OrderTotal = $orderTotal;
//
Some stuff with payment details
//
$DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType();
$DoECRequest = new DoExpressCheckoutPaymentRequestType();
$DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails;
$DoECReq = new DoExpressCheckoutPaymentReq();
$DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest;
$DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq);
我错过了一步还是调用了错误的功能。因为我试图打印我遇到的每个变量,而我的购物车的全部内容无处可寻。我觉得这很奇怪,因为交易的“orderTotal”与我原来的购物车相匹配。我可以在 SetExpressCheckout 步骤中存储我的原始订单,但由于贝宝已经有这些值,我发现它是多余的。
作为最后的手段,我确实使用 $paypalService->getLastRequest() 找到了购物车的内容,但严重的是,这是 paypal 返回的原始 XML,api 应该正确解析它:(。
谢谢阅读