在C#

时间:2015-09-08 07:51:52

标签: c# paypal paypal-rest-sdk

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

但是,在创建/发送发票时,我并不了解如何使用访问令牌和相关秘密来构建标题。

我正在使用C# .NET Invoicing SDKInvoicing Service API进行通信。

以下是我用来创建和发送发票的代码。

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 个答案:

答案 0 :(得分:1)

在黑暗中磕磕绊绊了一段时间后,我发现.NET Invoicing SDK负责创建标题。 InvoiceService有两种方法可以将标记和密钥分配给标头。有关详细信息,请参阅下文。

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