问题
been pulling my hair out for hours on this one...
i can't find a way to take an immediate payment via the paypal api without specifying a shipping address. i'm selling tickets that are delivered via email, no shipping is required.
there is info out there specifying you have to create a 'web experience profile'. however, one i can't find out how to pass the 'WebProfile()' to the payment and two, it's not what i want to do because the user then has to return the host website to authorise taking the payment adding an unnecessary step to my checkout.
one thing i have found is that if you specify the shipping address, the user can't change it once they get to paypal, they have to return to the host website to change the address. so for the moment, i'm using the postal address of the company but it's not ideal...
i just wanna take a payment in paypal without a shipping address, return to my website and take the payment!
is this even possible?! pretty sure it was/is with payment express?
for a bonus point, if someone can also tell me how to remove the 'You're almost done. You will confirm your payment on test facilitator's Test Store.' message (as i'm taking the payment the moment the user returns to my website) that would be amazin ;)
回答1:
Payments with PayPal do not require a shipping address to be completed. I'd recommend taking a look at the PayPal .NET SDK samples, which includes a Payment with PayPal sample that, when run, shows you the flow of creating, authorizing, and executing the payment.
Concerning the Web Experience Profile, when you make the payment you can optionally set an experience_profile_id
with the ID of a previously-created profile.
Here's the steps you'll want to follow to get all this working:
Step 1: Create a new web experience profile. The ID returned from this call can be re-used with every PayPal payment, so you should only need to do this once.
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.
// 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: 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();
Step 4: 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 });
来源:https://stackoverflow.com/questions/28951320/paypal-api-take-immediate-payment-without-a-shipping-address