gpt4 book ai didi

c# - 如何从控制台应用程序向 paypal 帐户汇款?

转载 作者:太空宇宙 更新时间:2023-11-03 15:57:33 25 4
gpt4 key购买 nike

我使用 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 批准页面的情况下向其他 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);
}
}
}

关于c# - 如何从控制台应用程序向 paypal 帐户汇款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56539900/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com