使用 PayPal 付款不需要填写送货地址。我建议看一下PayPal .NET SDK 示例,其中包括一个使用贝宝付款该示例在运行时向您显示创建、授权和执行付款的流程。
关于网络体验简介,当您付款时,您可以选择设置experience_profile_id
与先前创建的配置文件的 ID。
为了让这一切顺利进行,您需要遵循以下步骤:
Step 1:创建新的网络体验配置文件。从该调用返回的 ID 可以在每次 PayPal 付款中重复使用,因此您只需执行一次此操作。
var apiContext = new APIContext(); // APIContext with config info & credentials
// Create the web experience profile
var profile = new WebProfile
{
name = "My web experience profile",
presentation = new Presentation
{
brand_name = "My brand name",
locale_code = "US",
logo_image = "https://www.somesite.com/my_logo.png"
},
input_fields = new InputFields
{
no_shipping = 1
}
};
var createdProfile = profile.Create(apiContext);
Step 2:创建付款。
// Create the payment
var payment = new Payment
{
intent = "sale",
experience_profile_id = createdProfile.id,
payer = new Payer
{
payment_method = "paypal"
},
transactions = new List<Transaction>
{
new Transaction
{
description = "Ticket information.",
item_list = new ItemList
{
items = new List<Item>
{
new Item
{
name = "Concert ticket",
currency = "USD",
price = "20.00",
quantity = "2",
sku = "ticket_sku"
}
}
},
amount = new Amount
{
currency = "USD",
total = "45.00",
details = new Details
{
tax = "5.00",
subtotal = "40.00"
}
}
}
},
redirect_urls = new RedirectUrls
{
return_url = "http://www.somesite.com/order.aspx?return=true",
cancel_url = "http://www.somesite.com/order.aspx?cancel=true"
}
};
var createdPayment = payment.Create(apiContext);
Step 3:使用以下方式将买家重定向至 PayPalapproval_url
HATEOAS 链接包含在创建的付款中。
// Redirect buyer to PayPal to approve the payment...
var approvalUrl = createdPayment.GetApprovalUrl();
Step 4:买家批准付款并重定向回您的网站后,即可执行付款。
var payerId = Request.Params["PayerID"];
var paymentId = Request.Params["paymentId"];
var paymentToExecute = new Payment { id = paymentId };
var executedPayment = paymentToExecute.Execute(apiContext, new PaymentExecution { payer_id = payerId });