PayPal での支払いでは、配送先住所を入力する必要はありません。PayPal .NET SDK サンプルを参照することをお勧めします。このサンプルには、Payment with PayPalサンプルが含まれており、実行すると、支払いの作成、承認、および実行の流れが示されます。
Web Experience Profileに関しては、支払いを行うときexperience_profile_id
に、以前に作成したプロファイルの ID をオプションで設定できます。
これをすべて機能させるために従う必要がある手順は次のとおりです。
ステップ 1:新しい Web エクスペリエンス プロファイルを作成します。この呼び出しから返された ID は、PayPal での支払いごとに再利用できるため、これを行う必要があるのは 1 回だけです。
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 });