【问题标题】:paypal api: take immediate payment without a shipping addresspaypal api:无需送货地址即可立即付款
【发布时间】:2015-05-11 03:49:00
【问题描述】:

在这个上我已经拉了几个小时的头发了......

如果不指定送货地址,我找不到通过 paypal api 获取immediate payment 的方法。我正在销售通过电子邮件发送的门票,不需要送货。

那里有信息指定您必须创建“网络体验配置文件”。但是,一个我不知道如何将“WebProfile()”传递给付款,两个,这不是我想要做的,因为用户必须返回主机网站以授权接受付款,这增加了一个不必要的步骤到我的结帐处。

我发现的一件事是,如果您指定了送货地址,用户一旦到达贝宝就无法更改它,他们必须返回主机网站更改地址。所以目前,我使用的是公司的邮政地址,但这并不理想......

我只想在没有收货地址的情况下用贝宝付款,返回我的网站并付款!

这有可能吗?!很确定它是/现在是付款快递?

如果有人也可以告诉我如何删除“你快完成了”的话,那就加分吧。您将在测试服务商的测试商店确认您的付款。消息(因为我正在用户返回我的网站的那一刻付款),这将是惊人的;)

【问题讨论】:

    标签: c# paypal paypal-rest-sdk


    【解决方案1】:

    使用 PayPal 付款不需要填写送货地址。我建议您查看PayPal .NET SDK samples,其中包含一个Payment with PayPal 示例,该示例在运行时会显示创建、授权和执行付款的流程。

    关于网络体验配置文件,当您付款时,您可以选择使用先前创建的配置文件的 ID 设置 experience_profile_id

    您需要遵循以下步骤来完成所有这些工作:

    第 1 步:创建新的网络体验配置文件。此调用返回的 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_urlHATEOAS 链接将买家重定向到 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 });
    

    【讨论】:

    • 通过查看代码,我认为您已经成功了,我欠您一杯啤酒;)我认为“experience_profile_id = createdProfile.id”这一行是将“payer_id”传递给执行。我现在把这个放进去试试,真是太感谢你了!
    • 有趣...我的代码基于您提到的“使用 Paypal 付款”(github.com/paypal/PayPal-NET-SDK/blob/master/Samples/Source/…) 示例代码,因此很容易进入。第一次运行一切正常。随后的付款尝试给了我错误“具有此名称的个人资料已存在”。通过查看错误和 sdk 中的“PaymentExperienceCreate.aspx.cs”页面,看起来您需要在使用网络配置文件后将其删除?再试一次!
    • 是的,一旦您创建了 Web 体验配置文件 ID,您就无需继续创建它。只需缓存 ID,然后将其用于您创建的每笔付款。我会看看我是否可以用这个特定的用例更新示例项目。 :)
    • 嘿,我设法让它工作了——快乐的日子!有趣的是您只需创建一次网络配置文件?它似乎没有存储在我的贝宝沙盒帐户中以供查看......但我认为我在那里;)再次感谢您的帮助,它让生活变得更轻松(我现在还有一头浓密的头发……)
    • @jakewilliamson 很高兴听到!该配置文件存储在 PayPal 端,并且永远不会过期。您始终可以通过调用WebProfile.GetList() 并搜索它们来获取您创建的体验配置文件的列表。
    猜你喜欢
    • 2014-05-29
    • 2014-08-19
    • 2011-05-16
    • 2014-02-27
    • 2016-10-30
    • 2014-06-23
    • 2013-06-05
    • 2015-01-19
    • 2016-08-03
    相关资源
    最近更新 更多