Generating signatures for PayPal authentication header in C#

六月ゝ 毕业季﹏ 提交于 2019-12-08 18:03:25

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