简体   繁体   English

Paypal .Net SDK付款API代表第三方调用权限

[英]Paypal .Net SDK payment API calls on behalf of third party Permission

I use Paypal .Net SDK ( https://github.com/paypal/PayPal-NET-SDK ) for payment API calls. 我使用Paypal .Net SDK( https://github.com/paypal/PayPal-NET-SDK )进行支付API调用。 It needs an APIContext object to be passed in API calls. 它需要在API调用中传递APIContext对象。

By using clientid and clientsecret of my paypal app, I can obtain accesstoken to create the APIContext object. 通过使用我的贝宝应用程序的clientid和clientsecret,我可以获取accesstoken来创建APIContext对象。 But this makes payment into my merchant account. 但这会使付款进入我的商人帐户。

I wanted to make payment and refund API calls on behalf of other merchants. 我想代表其他商家进行付款和退款API调用。 For that I used Paypal Permission SDK ( https://github.com/paypal/permissions-sdk-dotnet ) to obatain permissions from Third Party Merchants. 为此,我使用了Paypal许可SDK( https://github.com/paypal/permissions-sdk-dotnet )从第三方商家获得许可。 Once a merchant grants permission, I get token and secret. 一旦商人授予许可,我就会获得令牌和秘密。 At this stage I cannot find any documentation how do I use that token and secret to call paypal API? 在此阶段,我找不到任何文档,该如何使用该令牌和密码来调用Paypal API?

Can anyone guide me how to use that token and secret (received from permission API) to make valid APIContext, which can be used to call various paypal.net sdk API calls? 谁能指导我如何使用令牌和机密(从权限API接收)来创建有效的APIContext,该APIContext可用于调用各种paypal.net sdk API调用?

My answer is a bit late, but may help others as I found this question when searching for how to do this. 我的回答有点晚了,但是当我在寻找如何做到这一点时发现了这个问题,可能会对别人有所帮助。

This applies if using the PayPal .NET SDK. 如果使用PayPal .NET SDK,则适用。

Create a PayPal.Api.Payee object and add this to your PayPal.Api.Transaction object that you use to make your payment. 创建一个PayPal.Api.Payee对象,并将其添加到用于付款的PayPal.Api.Transaction对象。

Example 1: 范例1:

var payee = new PayPal.Api.Payee()
{
    email = "test@example.com"
}

var transaction = new PayPal.Api.Transaction();
transaction.payee = payee;

Example 2: 范例2:

var paypal = new PayPal.Api.Transaction()
{
    description = "Transaction description.",
    invoice_number = "123",
    amount = new Amount()
    {
        currency = "USD",
        total = "100.00",
        details = new Details()
        {
            tax = "0",
            shipping = "25.00",
            subtotal = "75.00"
        }
    },
    item_list = new ItemList()
    {
        items = new List<Item>()
        {
            new Item()
            {
                name = "title",
                currency = "USD",
                price = "75.00",
                quantity = "1",
                sku = "MySKU"
            }
        }
    },
    payee = new Payee()
    {
        email = "email@example.com"
    }
};

Instead of email you could use merchant_id or phone to identify the third party to receive the funds. 您可以使用merchant_idphone代替email来标识接收资金的第三方。

Note: the third party must have granted your PayPal application the appropriate permission for the type of transaction you are attempting. 注意:第三方必须已为您的PayPal应用程序授予了您要尝试的交易类型的适当权限。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM