PayPal之前的Rest Api是不支援自定義物流地址的,最新升級版本的提供了這個服務(Payment Experience),大概步驟如下:
1.申請一個自定義的配置ID
自定義配置包括Logo,Url,Shipping物流地址方案,允許填寫備註等等
2.生成訂單付款的時候,將該ID傳送
示例程式碼在最新的SDK中都有Demo;如下:
一、Payment Experience Create
var apiContext = Configuration.GetAPIContext(); // Setup the profile we want to create var profile = new WebProfile() { name = Guid.NewGuid().ToString(), presentation = new Presentation() { brand_name = "Sample brand", locale_code = "US", logo_image = "https://www.paypal.com/" }, input_fields = new InputFields() { address_override = 1, allow_note = true, no_shipping = 2 } , flow_config = new FlowConfig() { bank_txn_pending_url = "https://www.paypal.com/", landing_page_type = "billing" } }; // Create the profile var response = profile.Create(apiContext); #region Cleanup // Cleanup by deleting the newly-created profile var retrievedProfile = WebProfile.Get(apiContext, response.id); retrievedProfile.Delete(apiContext); #endregion
InputFields.no_shipping:
// 摘要:
// Determines whether or not PayPal displays shipping address fields on the
// experience pages. Allowed values: `0`, `1`, or `2`. When set to `0`, PayPal
// displays the shipping address on the PayPal pages. When set to `1`, PayPal
// does not display shipping address fields whatsoever. When set to `2`, if
// you do not pass the shipping address, PayPal obtains it from the buyer's
// account profile. For digital goods, this field is required, and you must
// set it to `1`.
如何傳遞使用者的ShippingAddress?
ItemList itemList = new ItemList(); itemList.items = itms; //設定運送地址 ShippingAddress payaddress = new ShippingAddress(); payaddress.city = temp.City + "," + temp.Province; payaddress.line1 = temp.Address1; payaddress.line2 = temp.Address2; payaddress.phone = temp.TelPhone; payaddress.postal_code = temp.PostalCode; payaddress.country_code = temp.Country; payaddress.recipient_name = temp.FirstName + " " + temp.LastName; itemList.shipping_address = payaddress;