Php 如何向Paypal Express收银台提交地址?

Php 如何向Paypal Express收银台提交地址?,php,paypal-sandbox,paypal,Php,Paypal Sandbox,Paypal,我在写一些代码的过程中,将提交一个订单贝宝快捷结帐。不幸的是,我似乎无法让整个地址工作起来,而且我似乎也无法在API文档中找到关于它的很多信息。这是到目前为止我的代码 $config = array ( 'mode' => 'sandbox' , 'acct1.UserName' => '****removed*****', 'acct1.Password' => '******removed*******', 'acct1.Signatur

我在写一些代码的过程中,将提交一个订单贝宝快捷结帐。不幸的是,我似乎无法让整个地址工作起来,而且我似乎也无法在API文档中找到关于它的很多信息。这是到目前为止我的代码

$config = array (
    'mode' => 'sandbox' , 
    'acct1.UserName' => '****removed*****',
    'acct1.Password' => '******removed*******', 
    'acct1.Signature' => '*********removed***********'
);

$paypalService = new PayPal\Service\PayPalAPIInterfaceServiceService($config);
$paymentDetails= new PayPal\EBLBaseComponents\PaymentDetailsType();

// Dummy shipping address
// Obviously, in the final version, this would be passed in from a form
$shipping_address = new PayPal\EBLBaseComponents\AddressType();
$shipping_address->Name = "John Smith";
$shipping_address->Street1 = "123 Market Street";
$shipping_address->Street2 = "";
$shipping_address->CityName = "Columbus";
$shipping_address->StateOrProvince = "OH";
$shipping_address->PostalCode = "43017";
$shipping_address->Country = "US";

// A dummy item
// Once again, in a final version this would be passed in
$itemDetails = new PayPal\EBLBaseComponents\PaymentDetailsItemType();
$itemDetails->Name = 'Electro Lettuce Feeders';
$itemAmount = 1250.00;
$itemDetails->Amount = $itemAmount;
$itemQuantity = 1;
$itemDetails->Quantity = $itemQuantity;

// Add all items to the list
$paymentDetails->PaymentDetailsItem[0] = $itemDetails;

// The company is in NYS, so in the final version the
// sales tax rate will be passed in (NYS is destination-based)
$sales_tax_rate = 0.07;

// Order sub-total
$itemTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$itemTotal->currencyID = 'USD';
$itemTotal->value = ($itemAmount * $itemQuantity);

// Shipping total
$shippingTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$shippingTotal->currencyID = 'USD';
$shippingTotal->value = 2.00;

// Tax total
$taxTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$taxTotal->currencyID = 'USD';
$taxTotal->value = $itemTotal->value * $sales_tax_rate;

// Order total
$orderTotal = new PayPal\CoreComponentTypes\BasicAmountType();
$orderTotal->currencyID = 'USD';
$orderTotal->value = $itemTotal->value + $taxTotal->value + $shippingTotal->value;

$paymentDetails->TaxTotal = $taxTotal;
$paymentDetails->ItemTotal = $itemTotal;
$paymentDetails->ShippingTotal = $shippingTotal;
$paymentDetails->OrderTotal = $orderTotal;
$paymentDetails->PaymentAction = 'Sale';

// ***** Is the address from this object passed to Paypal?
$paymentDetails->ShipToAddress = $shipping_address;

$setECReqDetails = new PayPal\EBLBaseComponents\SetExpressCheckoutRequestDetailsType();
$setECReqDetails->PaymentDetails[0] = $paymentDetails;
$setECReqDetails->CancelURL = 'https://devtools-paypal.com/guide/expresscheckout/php?cancel=true';
$setECReqDetails->ReturnURL = 'https://devtools-paypal.com/guide/expresscheckout/php?success=true';

// ***** Or is this the address that will be passed to Paypal?
$setECReqDetails->Address = $shipping_address;

// ***** And can you choose to not pass in the billing address? Or is it required? *****
$setECReqDetails->BillingAddress = $shipping_address;

// ***** If this is set to 0, will the previously provided shipping address be shown
// ***** at all? Or will it just be "modify-able" unless you set this to 1?
$setECReqDetails->AddressOverride = 1;

$setECReqType = new PayPal\PayPalAPI\SetExpressCheckoutRequestType();
$setECReqType->Version = '104.0';
$setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;

$setECReq = new PayPal\PayPalAPI\SetExpressCheckoutReq();
$setECReq->SetExpressCheckoutRequest = $setECReqType;

$setECResponse = $paypalService->SetExpressCheckout($setECReq);

//var_dump($setECResponse);
$redirect_url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=".$setECResponse->Token;

return $app->redirect($redirect_url);
总而言之。。。 您将看到我的问题分布在整个代码中,但在这里它们都是总结

  • PaymentDetailsType()和SetExpressCheckoutRequestType()都具有地址属性。哪一个将传递给贝宝
  • 如果您传入了发货地址,API是否要求您传入账单地址
  • 如果您没有将AddressOverride设置为1,它是否应该显示您传入的地址

  • 但最后,我最重要的是想知道如何将地址传递到工作中。现在,无论我做什么尝试,我似乎都无法获得任何地址传递给Paypal。

    看到生成原始API请求而不是生成请求的代码会更有帮助。您正在使用的库应该能让您了解这一点。然后,您只需要确保在DoExpressCheckoutPayment中正确传递了地址参数


    如果你愿意,你可能想看看我的。用另一个库重新开始可能有点糟糕,但它使它变得非常快速和简单。它已经准备好了包含所有参数的文件,并且一切都准备就绪,因此您只需填写值,它每次都会工作。:)

    经过一番激烈的研究,我用贝宝的软件解决了这个问题。事实证明,SetExpressCheckoutRequestType()对象上的设置->地址是不推荐的。正确的方法是为PaymentDetailsType()对象设置->ShipToAddress

    然而,在我的情况下,什么都不起作用的原因是我的地址错了。我的拉链,在哥伦布地区的时候,严格地说是在都柏林。所以,Paypal产生了一个错误

    然而,Paypal没有向我显示错误信息,所以我无法知道是什么导致了错误。这就是API浏览器派上用场的地方;我填写了API资源管理器并尝试了我的请求——它给了我详细的错误信息

    从那时起,我还发现我可以通过使用以下工具查看详细的错误信息:

    var_dump($setECResponse);
    

    谢谢安德鲁!看起来你已经建立了一个很棒的类库。实际上,我可以使用Paypal的API explorer解决我的问题,但我肯定会在下一个项目中记住你的库——看起来它真的可以简化事情!