> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shoply.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Refund an order

> Refunds a completed order, all of it. Which `destination` an order can take is in `refund` on the order: a payment method that cannot send money back (crypto, always) can only be refunded as store credit or recorded.

Send an `Idempotency-Key` with this request. The order is marked refunded only once the payment provider has said the money is on its way, or the buyer has been credited.

Needs the `orders.refund` permission (Refund Orders).



## OpenAPI

````yaml /api-reference/openapi.json post /stores/{storeId}/orders/{orderId}/refund
openapi: 3.1.0
info:
  title: Shoply API
  version: '1'
  description: >-
    Everything a store's own server can do with a secret API key: its catalogue,
    orders, customers, marketing, finance and the rest of what the dashboard
    does. And the Customer API, which a buyer's own device asks with a token of
    theirs.
servers:
  - url: https://api.shoply.gg/v1
security:
  - apiKey: []
tags:
  - name: API key
  - name: Store
  - name: Domain
  - name: Payment methods
  - name: Analytics
  - name: Storefronts
  - name: Storefront code
  - name: Payment Routing
  - name: Custom payment methods
  - name: Products
  - name: Product pictures
  - name: Stock
  - name: Categories
  - name: Upsells
  - name: Subscriptions
  - name: Orders
  - name: Invoices
  - name: Reviews
  - name: Coupons
  - name: Coupon categories
  - name: Coupon pop-up
  - name: Sales
  - name: Blog
  - name: Search settings
  - name: Redirects
  - name: Sitemap
  - name: Cart Recovery
  - name: Email Marketing
  - name: Email Templates
  - name: Customers
  - name: Affiliates
  - name: Support Tickets
  - name: Blacklist
  - name: Fraud protection
  - name: Disputes
  - name: Finance
  - name: Tax
  - name: Expenses
  - name: Expense setup
  - name: API requests
  - name: Webhook endpoints
  - name: Webhook deliveries
  - name: Customer API
paths:
  /stores/{storeId}/orders/{orderId}/refund:
    post:
      tags:
        - Orders
      summary: Refund an order
      description: >-
        Refunds a completed order, all of it. Which `destination` an order can
        take is in `refund` on the order: a payment method that cannot send
        money back (crypto, always) can only be refunded as store credit or
        recorded.


        Send an `Idempotency-Key` with this request. The order is marked
        refunded only once the payment provider has said the money is on its
        way, or the buyer has been credited.


        Needs the `orders.refund` permission (Refund Orders).
      operationId: orders.refund
      parameters:
        - name: storeId
          in: path
          required: true
          description: >-
            The store's ID. A key reaches the store it was made in: `GET /key`
            answers which.
          schema:
            type: string
        - name: orderId
          in: path
          required: true
          description: The order. The ID in a checkout's address is the order's ID.
          schema:
            type: string
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                destination:
                  type: string
                  description: >-
                    `source`: back through the payment provider, to what paid.
                    `balance`: credit on the buyer's balance at the store.
                    `record`: only marked as refunded, because you returned the
                    money yourself.
                  enum:
                    - source
                    - balance
                    - record
                reason:
                  type: string
                  description: Why.
                  enum:
                    - requested
                    - duplicate
                    - fraudulent
                    - other
                amount:
                  type: number
                  description: >-
                    For `balance` only: how much to credit, from 0.01 up to what
                    was paid, with at most 2 decimals. Left out, all of it.
              required:
                - destination
                - reason
      responses:
        '200':
          description: It worked.
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    nullable: true
                  code:
                    nullable: true
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                      status:
                        type: string
                      destination:
                        type: string
              example:
                success: true
                message: null
                code: null
                data:
                  id: eab50b8e-fca6-4712-9b55-2f910b4bddf0
                  status: refunded
                  destination: record
        '401':
          $ref: '#/components/responses/NoKey'
        '403':
          $ref: '#/components/responses/NotAllowed'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/Refused'
        '429':
          $ref: '#/components/responses/TooMany'
      x-codeSamples:
        - lang: javascript
          label: Node.js
          source: |
            import Shoply from "@shoplygg/node";

            const shoply = new Shoply({ apiKey: process.env.SHOPLY_API_KEY });

            const result = await shoply.orders.refund("ORDER_ID", {
              destination: "source",
              reason: "requested",
            });
        - lang: php
          label: PHP
          source: |
            <?php

            require 'vendor/autoload.php';

            $shoply = new Shoply\Client(['apiKey' => getenv('SHOPLY_API_KEY')]);

            $result = $shoply->orders->refund('ORDER_ID', [
                'destination' => 'source',
                'reason' => 'requested',
            ]);
        - lang: python
          label: Python
          source: >
            import shoply


            client = shoply.Client()  # reads SHOPLY_API_KEY


            result = client.orders.refund("ORDER_ID", destination="source",
            reason="requested")
components:
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: false
      description: >-
        A word of your own for this one change, up to 180 letters, digits, dots,
        dashes, underscores and colons. Sent again with the same key, the
        request is not carried out twice: the first answer comes back, with
        `Idempotent-Replay: true`.
      schema:
        type: string
  responses:
    NoKey:
      description: >-
        No API key was sent, or the one sent is not a live key:
        `api_key_required`, `invalid_api_key`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Refusal'
    NotAllowed:
      description: >-
        The key is real and may not do this: `missing_scope` (with
        `requiredScope`), `ip_not_allowed`, `account_unavailable`, or
        `dashboard_only` for something only a person in the dashboard may do.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Refusal'
    NotFound:
      description: >-
        There is no such thing in this store: `not_found`. A store that is not
        the key's own is answered the same way.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Refusal'
    Refused:
      description: >-
        The request was understood and not carried out. `validation_failed` says
        what is wrong with each field under `errors`; other codes are the
        route's own.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Refusal'
    TooMany:
      description: >-
        The key has used up its budget for now: `rate_limited`. `Retry-After`
        says how many seconds to wait.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Refusal'
  schemas:
    Refusal:
      type: object
      properties:
        success:
          type: boolean
          example: false
        message:
          type: string
          description: What is wrong, in words for a person.
        code:
          type: string
          description: What is wrong, as a word that does not change.
        data:
          nullable: true
        errors:
          type: object
          description: >-
            For `validation_failed`: what is wrong with each field, by the
            field's name.
          additionalProperties:
            type: string
      required:
        - success
        - message
        - code
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        A secret API key, made under Developers in the dashboard:
        `Authorization: Bearer shoply_sk_...`

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.