All docs This doc
Skip to end of metadata
Go to start of metadata


Overview

The following operations allow you to work with sales and refunds. Click an operation name to see details on how to use it.

For a sample proxy service the illustrates how to work with sales and refunds, see Sample configuration.

OperationDescription

lookupSale

Looks up details on a sale transaction

refundSale

Refunds a completed payment

lookupRefund

Looks up details about a specific refund

Operation details

This section provides details on each of the operations.

Looking up details on a sale transaction 

Use this operation to get details about a sale transaction.

lookupSale
<paypal.lookupSale>
	<id>{$ctx:id}</id>
<paypal.lookupSale>

Properties

  • id: Required - The transaction ID.
Sample request

Following is a sample REST request that can be handled by the lookupSale operation.

Sample request for lookupSale
{
  "apiUrl":"https://api.sandbox.paypal.com",
  "accessToken":"nDMCVaHkksRjiUMOG7gBQB.T.u.U3a3UqhdPhbUY.so",
  "id":"6TA66076DE4666400"
}

Related PayPal documentation

https://developer.paypal.com/webapps/developer/docs/api/#look-up-a-sale

Refunding a sale 

Use this operation to refund a completed payment. For partial refunds, you can include an amount.

refundSale
<paypal.refundSale>
	<saleId>{$ctx:saleId}</saleId>
    <total>{$ctx:total}</total>
    <currency>{$ctx:currency}</currency>
</paypal.refundSale>

Properties

  • saleId: Required - ID of the sale.
  • total: Required - Total amount charged from the payer to the payee. In case of a refund, this is the refunded amount to the original payer from the payee. 10 characters max. with support for two decimal places.
  • currency: Required - 3-letter currency code. PayPal does not support all currencies.
Sample request

Following is a sample REST request that can be handled by the refundSale operation.

Sample request for refundSale
{
"apiUrl":"https://api.sandbox.paypal.com",
"accessToken":"dQf6yYTVBf6GxLA0kBNUX6s.dklqpYj.srMw80xpE4M",
"saleId":"6TA66076DE4666400",
"total":"0.03",
"currency":"USD"
}

Related PayPal documentation

https://developer.paypal.com/webapps/developer/docs/api/#refund-a-sale

Looking up a refund 

Use this call to get details about a specific refund. To get a list of your refunds, you can first get a list of payments. Within the list, you can see the state of the sale object as refunded and a refund object with the state of completed.

lookupRefund
<paypal.lookupRefund>  
	<refundId>{$ctx:refundId}</refundId>
</paypal.lookupRefund> 
Properties
  • refundId: Required - ID of the refund.
Sample request

Following is a sample REST request that can be handled by the lookupRefund operation.

Sample request for lookupRefund
{
    "apiUrl":"https://api.sandbox.paypal.com",
    "accessToken":"M9FW5RPolCL7IF4py-NNFZyLWPGwvbiZYHBmLGyYo24",
    "refundId":"3K261689LG295840H"
}

Related PayPal documentation

https://developer.paypal.com/webapps/developer/docs/api/#look-up-a-refund

Sample configuration

Following is a sample proxy service that illustrates how to connect to PayPal with the init operation and use the lookupSale operation. The sample request for this proxy can be found in lookupSale sample request. You can use this sample as a template for using other operations in this category.

 As a best practice, create a separate sequence for handling the response payload for errors. In the following sample, this sequence is "faultHandlerSeq".

Sample Proxy
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="paypal_lookupSale"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence onError="faultHandlerSeq">
         <property name="apiUrl" expression="json-eval($.apiUrl)"/>
         <property name="accessToken" expression="json-eval($.accessToken)"/>
         <property name="id" expression="json-eval($.id)"/>
         <paypal.init>
            <apiUrl>{$ctx:apiUrl}</apiUrl>
            <accessToken>{$ctx:accessToken}</accessToken>
         </paypal.init>
         <paypal.lookupSale>
            <id>{$ctx:id}</id>
         </paypal.lookupSale>
         <filter source="$axis2:HTTP_SC" regex="^[^2][\d][\d]">
            <then>
               <property name="ERROR_CODE" expression="$axis2:HTTP_SC"/>
               <switch source="$axis2:HTTP_SC">
                  <case regex="401">
                     <property name="ERROR_MESSAGE" value="Unauthorized"/>
                  </case>
                  <case regex="404">
                     <property name="ERROR_MESSAGE" value="Not Found"/>
                  </case>
                  <case regex="400">
                     <property name="ERROR_MESSAGE" value="Bad Request"/>
                     <property name="error_description" expression="json-eval($.error_description)"/>
                  </case>
               </switch>
               <sequence key="faultHandlerSeq"/>
            </then>
         </filter>
         <respond/>
      </inSequence>
      <outSequence>
         <log level="custom">
            <property name="text" value="An unexpected error occured"/>
            <property name="message" expression="get-property('ERROR_MESSAGE')"/>
         </log>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>
                                
  • No labels