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


Overview

The following operations allow you to work with captured payments. Click an operation name to see details on how to use it.

For a sample proxy service the illustrates how to work with captured payments, see Sample configuration.

OperationDescription

lookupCapturedPayment

Looks up details about a captured payment

refundCapturedPayment

Refunds a captured payment

Operation details

This section provides details on each of the operations.

Looking up a captured payment 

 Use this operation to get details about a captured payment.

lookupCapturedPayment
 <paypal.lookupCapturedPayment>
	<captureId>{$ctx:captureId}</captureId>
 </paypal.lookupCapturedPayment>
Properties
  • captureId: Required - The capture ID.
Sample request

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

Sample request for lookupCapturedPayment
{
	"apiUrl" : "https://api.sandbox.paypal.com",
	"accessToken" : "FiUebZi3SkXRUVmVXOZr4N0yIshk6fIk4KkXbK40MpY",
	"captureId" : "2DC87612EK520411B"
}

Related PayPal documentation

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

Refunding a captured payment 

Use this operation to refund a captured payment.

refundCapturedPayment
<paypal.refundCapturedPayment>
	<captureId>{$ctx:captureId}</captureId>
    <total>{$ctx:total}</total>
    <currency>{$ctx:currency}</currency>
    <details>{$ctx:details}</details>
</paypal.refundCapturedPayment>

Properties

  • captureId : Required - The capture ID.
  • total: Required - Total amount charged from the payer to the payee.  
  • currency: Required - 3-letter currency code.
  • details: Required - Additional details related to a payment amount.
Sample request

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

Sample request for refundCapturedPayment
{
  "apiUrl":"https://api.sandbox.paypal.com",
  "accessToken":"dd5X9uif8xBdq6cl6rxkxTawGkOU7Ghqh-b-.npfa.k",
   "captureId":"4AY782841P204802W",
    "currency":"USD",
    "total":"3.10",
    "details":{
          "subtotal":"3.41",
          "tax":"0.03",
          "shipping":"0.03"
        }
} 

Following is more information on the details property:

  • subtotal: Required - Subtotal (amount) of items being paid for before tax and shipping. 10 characters max. with support for two decimal places.
  • tax: Required - Amount charged for tax. 10 characters max. with support for two decimal places.
  • shipping: Required - Amount charged for shipping. 10 characters max. with support for two decimal places.
Related PayPal documentation

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

Sample configuration

Following is a sample proxy service that illustrates how to connect to PayPal with the init operation and use the lookupCapturedPayment operation. The sample request for this proxy can be found in lookupCapturedPayment 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_lookupCapturedPayment"
       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="captureId"
                   expression="json-eval($.captureId)"/>
         <paypal.init>
            <apiUrl>{$ctx:apiUrl}</apiUrl>
            <accessToken>{$ctx:accessToken}</accessToken>
         </paypal.init>
         <paypal.lookupCapturedPayment>
            <captureId>{$ctx:captureId}</captureId>
         </paypal.lookupCapturedPayment>
		 <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"/>
                     <property name="error_description" expression="json-eval($.message)"/>
                  </case>
				  <case regex="400">
                     <property name="ERROR_MESSAGE" value="Bad Request"/>
                     <property name="error_description" expression="json-eval($.message)"/>
                  </case>
               </switch>
               <sequence key="faultHandlerSeq"/>
            </then>
         </filter>
         <respond/>
      </inSequence>
      <outSequence>
        <send/>
      </outSequence>
   </target>
   <description/>
</proxy>


  • No labels