How do I accept an immediate payment without a shipping address?
You can optionally set an experience_profile_id with the ID of a previously-created profile when making a payment. Here’s how:
- Create a new web experience profile. You can reuse the ID returned from this call with each PayPal payment, so you should only need to do this once.
// 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);
- Create the payment.
// 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);
- Redirect the buyer to PayPal using the approval_url HATEOAS link included with the created payment.
// Redirect buyer to PayPal to approve the payment...
var approvalUrl = createdPayment.GetApprovalUrl();
- Once the buyer approves the payment and is redirected back to your site, execute the payment.
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 });
See also:
Web experience profiles
Process PayPal Payments
Was this article helpful?