如何使用c#为paypal CreateInvoice api创建SOAP XML请求消息

时间:2012-11-17 05:32:17

标签: c# soap paypal paypal-sandbox invoice

我为PayPal创建了一个沙盒测试帐户。 我想在C#中使用SOAP xml格式使用PayPal api CreateInvoice,SendInvoice和CreateAndSendInvoice。来自x.com的文档至少以基本的soap xml格式没有显示任何已完成的请求消息,而是仅显示soap xml标记的标题部分和定义。

一些例子是JSON格式,但它不是我喜欢的格式,它重量轻但人类可读。 SDK使用的是NVP格式,虽然它们有SOAP选项,但代码无法为有效负载组成soap xml格式。

我需要已完成的soap xml请求消息,至少包含createinvoice所需的字段。

到目前为止,我仍在搜索stackoverflow。

1 个答案:

答案 0 :(得分:0)

API参考提供SOAP请求的图形表示。例如,您可以查看CreateAndSendInvoice并查看可能包含在XML / SOAP请求中的所有标记以及应如何嵌套所有标记。

如果您打算自己构建XML而不是使用WSDL,那么实际上不需要为SOAP格式化它。这是我刚刚成功运行的CreateInvoice XML请求示例...

<?xml version="1.0" encoding="utf-8"?>
<CreateInvoiceRequest xmlns="http://svcs.paypal.com/types/ap">
  <requestEnvelope xmlns="">
    <detailLevel>ReturnAll</detailLevel>
    <errorLanguage>en_US</errorLanguage>
  </requestEnvelope>
  <invoice xmlns="">
    <merchantEmail xmlns="">sandbo_1215254764_biz@angelleye.com</merchantEmail>
    <payerEmail xmlns="">sandbo_1204199080_biz@angelleye.com</payerEmail>
    <number xmlns="">12Z3-ABCDE</number>
    <merchantInfo xmlns="">
      <firstName xmlns="">Tester</firstName>
      <lastName xmlns="">Testerson</lastName>
      <businessName xmlns="">Testers, LLC</businessName>
      <phone xmlns="">555-555-5555</phone>
      <fax xmlns="">555-555-5556</fax>
      <website xmlns="">http://www.domain.com</website>
      <customValue xmlns="">Some custom info.</customValue>
      <address xmlns="">
        <line1 xmlns="">123 Main St.</line1>
        <city xmlns="">Grandview</city>
        <state xmlns="">MO</state>
        <postalCode xmlns="">64030</postalCode>
        <countryCode xmlns="">US</countryCode>
      </address>
    </merchantInfo>
    <itemList xmlns=""><item xmlns="">
      <name xmlns="">Test Widget 1</name>
      <description xmlns="">This is a test widget #1</description>
      <date xmlns="">2012-02-18</date>
      <quantity xmlns="">1</quantity>
      <unitPrice xmlns="">10.00</unitPrice>
      </item><item xmlns="">
      <name xmlns="">Test Widget 2</name>
      <description xmlns="">This is a test widget #2</description>
      <date xmlns="">2012-02-18</date>
      <quantity xmlns="">2</quantity>
      <unitPrice xmlns="">20.00</unitPrice>
      </item></itemList>
    <currencyCode xmlns="">USD</currencyCode>
    <paymentTerms xmlns="">DueOnReceipt</paymentTerms>
    <note xmlns="">This is a test invoice.</note>
    <merchantMemo xmlns="">This is a test invoice.</merchantMemo>
    <billingInfo xmlns="">
      <firstName xmlns="">Tester</firstName>
      <lastName xmlns="">Testerson</lastName>
      <businessName xmlns="">Testers, LLC</businessName>
      <phone xmlns="">555-555-5555</phone>
      <fax xmlns="">555-555-5556</fax>
      <website xmlns="">http://www.domain.com</website>
      <customValue xmlns="">Some custom info.</customValue>
      <address xmlns="">
        <line1 xmlns="">123 Main St.</line1>
        <city xmlns="">Grandview</city>
        <state xmlns="">MO</state>
        <postalCode xmlns="">64030</postalCode>
        <countryCode xmlns="">US</countryCode>
      </address>
    </billingInfo>
    <shippingInfo xmlns="">
      <firstName xmlns="">Tester</firstName>
      <lastName xmlns="">Testerson</lastName>
      <businessName xmlns="">Testers, LLC</businessName>
      <phone xmlns="">555-555-5555</phone>
      <fax xmlns="">555-555-5556</fax>
      <website xmlns="">http://www.domain.com</website>
      <customValue xmlns="">Some custom info.</customValue>
      <address xmlns="">
        <line1 xmlns="">123 Main St.</line1>
        <city xmlns="">Grandview</city>
        <state xmlns="">MO</state>
        <postalCode xmlns="">64030</postalCode>
        <countryCode xmlns="">US</countryCode>
      </address>
    </shippingInfo>
    <shippingAmount xmlns="">10.00</shippingAmount>
    <logoUrl xmlns="">https://www.usbswiper.com/images/angelley-clients/cpp-header-image.jpg</logoUrl>
    <referrerCode xmlns="">AngellEYE_PHPClass</referrerCode>
  </invoice>
</CreateInvoiceRequest>