簡體   English   中英

如何從控制台應用程序匯款到貝寶賬戶?

[英]How send money to paypal account from console app?

我使用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 批准頁面的情況下向其他貝寶錢包匯款?

通過使用付款解決(正如我所理解的,付款用於客戶到商家的轉賬)。

    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);
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM