在C#中为PayPal身份验证标头生成签名 [英] Generating signatures for PayPal authentication header in C#

查看:124
本文介绍了在C#中为PayPal身份验证标头生成签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是代表第三方商家将发票发送到另一个Paypal帐户.我正在使用权限服务来成功获取权限,从而产生访问令牌和关联的机密.

My objective is to send an invoice on behalf of a 3rd party merchant to another paypal account. I am using the permissions service to successfully obtain permissions, resulting in an access token and associated secret.

但是,我不明白在创建/发送发票时如何使用访问令牌和关联的机密信息来构建标题.

However, I don't understand how to use the access token and associated secret to build the headers when creating/sending the invoice.

我正在使用 C#.NET发票SDK 开发票服务API .

这是我用来创建和发送发票的代码.

Here is the code I am using to create and send an invoice.

RequestEnvelope envelopeRequest = new RequestEnvelope();
envelopeRequest.errorLanguage = "en_GB";

List<InvoiceItemType> invoiceItemList = new List<InvoiceItemType>();

InvoiceItemType invoiceItem = new InvoiceItemType("Item", Convert.ToDecimal("2"), Convert.ToDecimal("4.00"));
invoiceItemList.Add(invoiceItem);

InvoiceItemListType itemList = new InvoiceItemListType(invoiceItemList);

InvoiceType invoice = new InvoiceType("jb-us-seller@paypal.com", "jbui-us-personal1@paypal.com", itemList, "USD");

CreateAndSendInvoiceRequest requestCreateAndSendInvoice = new CreateAndSendInvoiceRequest(envelopeRequest, invoice);

InvoiceService service = new InvoiceService();

responseCreateAndSendInvoice = service.CreateAndSendInvoice(requestCreateAndSendInvoice);

推荐答案

在黑暗中绊倒了一段时间后,我发现.NET Invoicing SDK负责创建标头. InvoiceService有两种将令牌和机密分配给标头的方法.有关详情,请参见下文.

After stumbling around in the dark for quite some time, I came to find that the .NET Invoicing SDK takes care of creating the headers. InvoiceService has two methods which assign the token and the secret to the header. See below for details.

RequestEnvelope envelopeRequest = new RequestEnvelope();
envelopeRequest.errorLanguage = "en_GB";

List<InvoiceItemType> invoiceItemList = new List<InvoiceItemType>();

InvoiceItemType invoiceItem = new InvoiceItemType("Item", Convert.ToDecimal("2"), Convert.ToDecimal("4.00"));
invoiceItemList.Add(invoiceItem);

InvoiceItemListType itemList = new InvoiceItemListType(invoiceItemList);

InvoiceType invoice = new InvoiceType("shop1@test.co.uk", "buyer1@gmail.com", itemList, "USD");

CreateAndSendInvoiceRequest requestCreateAndSendInvoice = new CreateAndSendInvoiceRequest(envelopeRequest, invoice);

Dictionary<string, string> list = new Dictionary<string, string>();
list.Add("mode", "sandbox");
list.Add("account1.apiUsername", "contact-facilitator_api1.testdomain.com");
list.Add("account1.apiPassword", "xxxx");
list.Add("account1.apiSignature", "xxxx--xxx");

InvoiceService service = new InvoiceService(list);

service.SetAccessToken(accessToken);
service.SetAccessTokenSecret(secret);

responseCreateAndSendInvoice = service.CreateAndSendInvoice(requestCreateAndSendInvoice); 

这篇关于在C#中为PayPal身份验证标头生成签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆