【问题标题】:How send money to paypal account from console app?如何从控制台应用程序向贝宝帐户汇款?
【发布时间】:2019-10-25 15:38:18
【问题描述】:

我使用PayPal-NET-SDK 与 PayPal 系统(sanbox)进行交互。我有下一个代码:

    static void Main(string[] args)
    {
        try
        {
            var config = ConfigManager.Instance.GetProperties();
            var accessToken = new OAuthTokenCredential(config).GetAccessToken();
            var apiContext = new APIContext(accessToken);

            var payment = Payment.Create(apiContext, new Payment
            {
                intent = "order",
                payer = new Payer
                {
                    payment_method = "paypal"
                },
                transactions = new List<Transaction>
                {
                    new Transaction
                    {
                        description = "Transaction description.",
                        invoice_number = "002",
                        amount = new Amount
                        {
                            currency = "USD",
                            total = "15.00",
                        },
                        payee = new Payee
                        {
                            email = "test1@gmail.com"
                        }
                    }
                },
                redirect_urls = new RedirectUrls
                {
                    return_url = "site for redirect", // in my code there is normal url
                    cancel_url = "site for redirect""
                }
            });

            var approval = payment.GetTokenFromApprovalUrl();

            var url = payment.GetApprovalUrl();


            payment.token = approval;

            var response = payment.Execute(apiContext, new PaymentExecution {payer_id = "C598R54Q6P39G" });
        }
        catch (PaymentsException e)
        {
            Console.WriteLine(e.Response);
        }
    }

执行此代码后,我收到来自 PayPal 的错误请求错误(“付款人未批准付款”)。如果在调试中转到 url 中的链接,我会进入 PayPal 确认页面,并在按下继续按钮后,付款执行没有异常(但资金仍然相同,钱没有发送)。如何在不重定向到 PayPal 批准页面的情况下向其他贝宝钱包汇款?

【问题讨论】:

    标签: c# .net paypal


    【解决方案1】:

    通过使用付款解决(据我了解,付款用于客户到商家的转账)。

        static void Main(string[] args)
        {
            try
            {
                // Authenticate with PayPal
                var config = ConfigManager.Instance.GetProperties();
                var accessToken = new OAuthTokenCredential(config).GetAccessToken();
                var apiContext = new APIContext(accessToken);
    
                var payout = Payout.Create(apiContext, new Payout
                {
                    sender_batch_header = new PayoutSenderBatchHeader
                    {
                        email_subject = "Hello payout",
                        sender_batch_id = "ilab_Payout002",
                        recipient_type = PayoutRecipientType.EMAIL
                    },
                    items = new List<PayoutItem>
                    {
                        new PayoutItem
                        {
                            amount = new Currency
                            {
                                currency = "USD",
                                value = "17.5"
                            },
                            note = "Exchange is done!",
                            receiver = "ilab-test1@gmail.com",
                            recipient_type = PayoutRecipientType.EMAIL,
                            sender_item_id = "121341"
                        }
                    },
                });
            }
            catch (PaymentsException e)
            {
                Console.WriteLine(e.Response);
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-03
      • 2017-07-04
      • 2013-06-10
      • 2021-11-04
      • 2013-06-01
      • 2013-05-10
      相关资源
      最近更新 更多