Generating signatures for PayPal authentication header in C#

被刻印的时光 ゝ 提交于 2019-12-08 03:28:20

问题


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.

I am using the C# .NET Invoicing SDK to communicate with the Invoicing Service 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);

回答1:


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


来源:https://stackoverflow.com/questions/32452137/generating-signatures-for-paypal-authentication-header-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!