使用 PayPal 付款不需要填写送货地址。我建议您查看PayPal .NET SDK 示例,其中包括使用 PayPal 支付的示例,该示例在运行时会向您显示创建、授权和执行支付的流程。
关于Web Experience Profile,当您付款时,您可以选择experience_profile_id
使用先前创建的配置文件的 ID 设置一个。
以下是您要完成所有这些工作的步骤:
第 1 步:创建新的 Web 体验配置文件。此调用返回的 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);
第 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);
第 3 步:approval_url
使用创建的付款中包含的 HATEOAS 链接将买家重定向到 PayPal 。
// Redirect buyer to PayPal to approve the payment...
var approvalUrl = createdPayment.GetApprovalUrl();
第 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 });