PHP Paypal SOAP SetExpressCheckout Request Message Example

This Paypal SOAP API operation page and this Paypal SOAP API Basic page are developed by paypal.com in order to tell us how to use SetExpressCheckOut Request message in SOAP way.

However, the page does not tell us "EXACTLY HOW" to write the XML because they do not provide any exact example on how to format the XML (It only mention a little bit in the soap api basic page, but I get little value from reading this...).

I personally think that this document is badly written, because you still don't know how to get start by reading that.  Therefore, I test a lot of things in this poorly written documentation, and supplement it by an example here.

If you want to find out how do you format your XML correctly, here is the example.

Attention

  1. This example DOES NOT CONTAIN ALL options.  It covers around 60 - 70% options in the page.  But you should be comfortable on how to make use of that Paypal documentation easily.
  2. If you define a list of items in XML, but it does not display in paypal page, chances are you defined some other paypal parameters that stop the display of purchased items.  Please refer to the XML below to find out which parameters do so.
  3. This paypal XML is for version 87.0.  Therefore some parameters are deprecated if you refer the paypal soap api operation page.

Let's started:


<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema
instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Header>
        <RequesterCredentials xmlns="urn:ebay:api:PayPalAPI">
            <Credentials xmlns="urn:ebay:apis:eBLBaseComponents">
                <Username>enter-your-paypal-api-username</Username>
                <Password> enter-your-paypal-api-password</Password>
                <Subject></Subject>
            </Credentials>
        </RequesterCredentials>
    </soap:Header>
    <soap:Body>
        <SetExpressCheckoutReq xmlns="urn:ebay:api:PayPalAPI">

            <SetExpressCheckoutRequest>
                <Version xmlns="urn:ebay:apis:eBLBaseComponents">87.0</Version>

                <SetExpressCheckoutRequestDetails xmlns="urn:ebay:apis:eBLBaseComponents">
                    <ReturnURL>http://localhost/your-return-url.php</ReturnURL>
                    <CancelURL>http://localhost/your-cancel-url.php</CancelURL>
                    <ReqConfirmShipping>0</ReqConfirmShipping>
                    <FundingSourceDetails>
                        <AllowedPaymentMethod>InstantOnly</AllowedPaymentMethod>
                    </FundingSourceDetails>

                    <NoShipping>1</NoShipping>
                    <AllowNote>1</AllowNote>
                    <AddressOverride>0</AddressOverride>
                    <LocaleCode>US</LocaleCode>
                    <PageStyle>PayPal</PageStyle>
                    <BuyerEmail>test@gmail.com</BuyerEmail>
                    <ChannelType>Merchant</ChannelType>
                    <BrandName>Mywebsite.com</BrandName>

                    <!--
                    <cpp-header-image>http://www.yourwebsite.com/logo.png</cpp-header-image>
                    <cpp-header-back-color>F0F1F2</cpp-header-back-color>
                    <cpp-payflow-color>F0F1F2</cpp-payflow-color>
                    -->

                    <PaymentDetails>
                        <OrderTotal currencyID="USD">555</OrderTotal>
                        <!-- This amount does not include tax, even if it is defined in PaymentDetailsItem-->
                        <ItemTotal currencyID="USD">500</ItemTotal>

                        <ShippingTotal currencyID="USD">15</ShippingTotal>
                        <HandlingTotal currencyID="USD">35</HandlingTotal>
                        <TaxTotal currencyID="USD">5</TaxTotal>
                        <InvoiceID>12345</InvoiceID>

                        <!--This will not show if items are shown-->
                        <OrderDescription>(Optional) Description of items the buyer is purchasing.</OrderDescription>

                        <!--These items will make the item list disappear/not show-->
                        <!--
                        <PaymentAction>Order</PaymentAction>
                        <NoteText>(Optional) Note to the merchant.</NoteText>
                        <ShippingDiscount currencyID="USD">-5</ShippingDiscount>
                        <InsuranceOptionOffered>true</InsuranceOptionOffered>
                        <InsuranceTotal currencyID="USD">20</InsuranceTotal>
                        <InsuranceOptionOffered>false</InsuranceOptionOffered>
                        -->

                        <ShipToAddress>
                            <Name>I love you</Name>
                            <Street1>1  1  1, Unit 1</Street1>
                            <Street2></Street2>
                            <CityName>Melbourne</CityName>
                            <StateOrProvince>Australia</StateOrProvince>
                            <PostalCode>2083</PostalCode>
                            <Country>AU</Country>
                            <Phone></Phone>
                        </ShipToAddress>
                        
                        <!--Total amount is 101-->
                        <PaymentDetailsItem>
                            <Name>Name 1</Name>
                            <Amount currencyID="USD">100</Amount>
                            <Quantity>1</Quantity>
                            <ItemCategory>Physical</ItemCategory>
                            <Description>Description 1</Description>
                            <Number>num100</Number>
                            <Tax currencyID="USD">1</Tax>
                            <ItemWeight>10</ItemWeight>
                            <ItemLength>12</ItemLength>
                            <ItemWidth>13</ItemWidth>
                            <ItemHeight>15</ItemHeight>
                            <ItemURL>http://www.items.com?productid=1</ItemURL>
                        </PaymentDetailsItem>

                        <!--Total amount 404-->
                        <PaymentDetailsItem>
                            <Name>Name 2</Name>
                            <Amount currencyID="USD">200</Amount>
                            <Quantity>2</Quantity>
                            <ItemCategory>Physical</ItemCategory>
                            <Description>Description 2</Description>
                            <Number>num200</Number>
                            <Tax currencyID="USD">2</Tax>
                            <ItemWeight>20</ItemWeight>
                            <ItemLength>22</ItemLength>
                            <ItemWidth>23</ItemWidth>
                            <ItemHeight>25</ItemHeight>
                            <ItemURL>http://www.items.com?productid=2</ItemURL>
                        </PaymentDetailsItem>
                        
                    </PaymentDetails>
                </SetExpressCheckoutRequestDetails>
            </SetExpressCheckoutRequest>
        </SetExpressCheckoutReq>
    </soap:Body>
</soap:Envelope>

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services

Using wget bypass htaccess username password 401 authorization