gpt4 book ai didi

php - 如何向 Paypal Express Checkout 提交地址?

转载 作者:太空宇宙 更新时间:2023-11-03 16:32:59 25 4
gpt4 key购买 nike

我正在编写一些代码,用于向 Paypal Express Checkout 提交订单。不幸的是,我似乎无法让整个地址正常工作,而且我似乎也无法在 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);

总结...

你会看到我的问题分布在整个代码中,但在这里它们都被总结了。

  1. PaymentDetailsType()SetExpressCheckoutRequestType() 都具有地址属性。哪一个将被传递到 Paypal?
  2. 如果您传递送货地址,API 是否要求您传递账单地址?
  3. 如果您不将 AddressOverride 设置为 1,它是否应该显示您传入的地址?

但最后,我最重要的只是想知道如何让地址传递起作用。 =).现在,无论我尝试什么,我似乎都无法获得任何地址以传递给 Paypal。

最佳答案

与生成请求的代码相比,查看生成的原始 API 请求会更有帮助。您正在使用的图书馆应该为您提供一些查看方式。然后你只需要确保在 DoExpressCheckoutPayment 中正确传递地址参数。

如果你喜欢,你可能想看看我的PHP class library for PayPal .从另一个库开始可能有点糟糕,但它使它变得非常快速和容易。它准备了包含所有参数的文件,一切都准备就绪,因此您需要做的就是填写值,它每次都能正常工作。 :)

关于php - 如何向 Paypal Express Checkout 提交地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20332616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com