In this article

Overview

You can use this Snap to generate refund transactions for an order.

Prerequisites

None.

Support for Ultra Pipelines

Works in Ultra Pipelines

Limitations

  • API versions: Shopify releases new API versions every quarter. Each stable version is supported only for a minimum of 12 months. Part of a Shopify API is deprecated if it becomes unnecessary, unsafe, or outdated. The API’s are marked as deprecated when they are removed in a newer version of the API. The deprecation is then retroactively applied to previous stable versions of the API.
  • API Rate Limit: All Shopify APIs are rate-limited. Shopify uses various strategies to enforce rate limits, such as Calculated query cost, Request-based limit, and Time-based limit. 
    Shopify Snap Pack uses admin APIs, which are applicable for Request-based limit. If the APIs cross the rate limit, the Snap fails.

    API

    Rate-limiting method

    Standard limit

    Shopify Plus limit

    Admin API

    (GraphQL)

    Calculated query cost

    50 points/second

    100 points/second

    Admin API

     (REST)

    Request-based limit

    2 requests/second

    4 requests/second



  • Order discount is applied for invalid discount codes also. The discount percentage or amount is allotted more than percentage/amount set for valid discount code. For example, summer20 is a valid discount code, which should apply 20% of discount. However, if we provide discount percentage as 50%, then it applies 50% discount ignoring the set discount percentage.
  • If you provide an invalid value for Transaction ID or Parent ID, the Snap is not validated. The Snap ignores the invalid values and processes the operation.

Known Issues

None.

Snap Input and Output

Input/OutputType of ViewNumber of ViewsExamples of Upstream and Downstream SnapsDescription
Input 

Document


  • Min:1
  • Max:1
  • Mapper
  • Copy

The order details, such as time of order creation, order ID, order note, amount, and currency code.

Output

Document


  • Min:1
  • Max:1
  • Mapper
  • Get Order
  • Order Refund
  • Group By N

Retrieves a specific refund.

Snap Settings


Field NameField DependencyDescription
Label*N/A

Specify the name for the Snap. You can modify the default name to be specific and meaningful, especially if you have more than one of the same Snap in your Pipeline.

Default Value: Calculate Order Refund
Example: Ord_354

Version*N/A

Specify the Shopify API version. Alternatively, click the Suggestion  icon to fetch the list of supported Shopify API versions and select a version. 

Default Value: 2021-07
Example: 2021-04

Order Id*N/ASpecify a unique identifier for the order.

Default Value: N/A
Example: Ord_254

Number Of RetriesN/A

Specify an integer value to set the maximum number of reconnection attempts that the Snap must perform, in case of connection failure or timeout.

Default Value: 1
Example: 2

Retry Interval (Seconds)N/A

Specify the duration in seconds for which the Snap must wait between two reconnection attempts, until the number of retries is reached.

Default Value: 1
Example: 5

Snap ExecutionN/A

Select one of the three modes in which the Snap executes. Available options are:

  • Validate & Execute: Performs limited execution of the Snap, and generates a data preview during Pipeline validation. Subsequently, performs full execution of the Snap (unlimited records) during Pipeline runtime.
  • Execute only: Performs full execution of the Snap during Pipeline execution without generating preview data.
  • Disabled: Disables the Snap and all Snaps that are downstream from it.

Default Value: Execute only
Example: Validate & Execute


Example

Calculating Refund For An Order

This example Pipeline demonstrates how to calculate refund for an order and subsequently create an Order Refund using the Calculate Order Refund and Create Order Refund Snaps.

First, we pass the following customer and order data using the JSON Generator Snap.

[
    {
        "email": "john.doe@snaplogic.com",
        "phone": "9533322211",
        "test": true,
        "line_items": [
            {
                "variant_id": 40273525866686,
                "product_id": 6863881928894,
                "quantity": 1
            }
        ],
        "transactions": [
            {
                "kind": "sale",
                "status": "success",
                "amount": 5000
            }
        ],
        "billing_address": {
            "address1": "Sector-1",
            "address2": "Apartment 5",
            "city": "Vishakapatnam",
            "company": null,
            "country": "India",
            "first_name": "John",
            "last_name": "Doe",
            "phone": "9533322211",
            "province": "AP",
            "zip": "530046",
            "name": "John",
            "country_code": "IN"
        },
        "shipping_address": {
            "address1": "Sector-1",
            "address2": "Apartment 5",
            "city": "Vishakapatnam",
            "company": null,
            "country": "India",
            "first_name": "John",
            "last_name": "Doe",
            "phone": "9533322211",
            "province": "AP",
            "zip": "530046",
            "name": "John",
            "country_code": "IN"
        }
    }
]

Upon validation, we see the following data in the output preview of the Snap.

[
	{
		"email":"john.doe@snaplogic.com"
		"phone":"9533322211"
		"test":true
		"line_items":
	[
	{
		"variant_id":40273525866686
		"product_id":6863881928894
		"quantity":1
	}
]
		"transactions":
[
	{
		"kind":"sale"
		"status":"success"
		"amount":5000
	}
]
		"billing_address":
	{
		"address1":"Sector-1"
		"address2":"Apartment 5"
		"city":"Vishakapatnam"
		"company":null
		"country":"India"
		"first_name":"John"
		"last_name":"Doe"
		"phone":"9533322211"
		"province":"AP"
		"zip":"530046"
		"name":"John"
		"country_code":"IN"
}
		"shipping_address":
	{
		"address1":"Sector-1"
		"address2":"Apartment 5"
		"city":"Vishakapatnam"
		"company":null
		"country":"India"
		"first_name":"John"
		"last_name":"Do"
		"phone":"9533322211"
		"province":"AP"
		"zip":"530046"
		"name":"Rohit"
		"country_code":"IN"
		}
	}
]


Next, we configure the Create Order Snap to create an order. On validation, the Snap creates an order.

Create Order Snap ConfigurationOutput

Next, we configure the first Mapper Snap to map the ID against the Order Id column.

Upon validation, the Snap generates the following data in the output preview of the Snap.

Next, we configure the JSON Splitter Snap to split each item in the line items into separate documents. We specify the $line_items for Json Path and $order_id (path of the object) for Include Path to include in the output.

Upon validation, we see the value for each line item in the order separately.

Next, we configure the second Mapper Snap to map the following attributes in the line item.

Upon validation, the Snap generates the line item data as configured.

Next, we use the Group by Fields Snap to group the line items by Order ID. However, we are only interested in refund line items; hence, we specify refund_line_items in the Target field. Upon validation we see the list of items grouped under refund_line_items object.

Group By Fields Snap ConfigurationOutput

Next, we use the Mapper Snap to pass the refund line items output from the upstream Snap to calculate order refund subsequently.

Upon validation, the Snap generates the refund order data as follows.

Next, we configure the Calculate Order Refund Snap to calculate the refund for the order.

Upon validation, the Snap generates the status of the refund (full refund in this case) and other details, such as quantity, line_item_id, orderId, and location_id.

Next, we use the fourth and the last Mapper Snap in our Pipeline to pass the details as highlighted below to use the Snap's output in the downstream Snap for creating an order refund.

We configure the Create Order Refund Snap to create a refund for the order.

Upon validation, the Snap generates a refund for the order and we can view the related refund data in the output preview of the Snap.

We further use the JSON formatter Snap to format the JSON file, and write the document on to SL database using the File Writer Snap.

Download this Pipeline.



See Also