paypal api: take immediate payment without a shipping address

后端 未结 1 922
情书的邮戳
情书的邮戳 2021-01-18 06:37

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 sel

相关标签:
1条回答
  • 2021-01-18 06:58

    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 });
    
    0 讨论(0)
提交回复
热议问题