Skip to main content

Documentation

Create an Order

Create an order for goods.

For services, see Create Subscription.

The payment method used in the process is the customer’s default payment method. See Pay an Order.

This method triggers the Order Created webhook. This webhook contains the same information as the response.

Code Samples
    • .NET

      • using System;
        using System.Text.Json;
        
        namespace RapydApiRequestSample
        {
            class Program
            {
                static void Main(string[] args)
                {
                    try
                    {
                        var metadata = new
                        {
                            merchant_defined = true
                        };
        
                        var items = new Object[]
                        {
                            new
                            {
                                type = "sku",
                                currency = "USD",
                                amount = 200,
                                quantity = 2,
                                parent = "sku_2cc9627661754e0a0b78397a62c9d9f2",
                                description = "Deluxe Gamer's Chair",
                            },
                            new
                            {
                                type = "shipping",
                                amount = 10,
                                currency = "USD",
                                description = "Shipping",
                            }
                        };
        
                        var shipping_address = new
                        {
                            name = "John Doe",
                            line_1 = "123 State Street",
                            line_2 = "Apt. 34",
                            line_3 = "",
                            city = "Anytown",
                            district = "",
                            canton = "",
                            state = "NY",
                            country = "US",
                            zip = "12345",
                            phone_number = "12125559999",
                            metadata,
                        };
        
                        var requestObj = new
                        {
                            customer = "cus_c697782cd18d3862e40e991fe4f0ca34",
                            currency = "USD",
                            external_coupon_code = "squeee",
                            items,
                            shipping_address,
                            tax_percent = 0,
                            upstream_id = "GZC12345",
                            email = "johndoe@rapyd.net",
                            metadata,
                        };
        
                        string request = JsonSerializer.Serialize(requestObj);
        
                        string result = RapydApiRequestSample.Utilities.MakeRequest("POST", "/v1/orders", request);
        
                        Console.WriteLine(result);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("Error completing request: " + e.Message);
                    }
                }
            }
        }
        
    • JavaScript

      • const makeRequest = require('<path-to-your-utility-file>/utilities').makeRequest;
        
        async function main() {
          try {
            const body = {
              customer: 'cus_c697782cd18d3862e40e991fe4f0ca34',
              currency: 'USD',
              external_coupon_code: 'squeee',
              items: [
                {
                  type: 'sku',
                  currency: 'USD',
                  amount: 200,
                  quantity: 2,
                  parent: 'sku_2cc9627661754e0a0b78397a62c9d9f2',
                  description: "Deluxe Gamer's Chair"
                },
                {
                  type: 'shipping',
                  amount: 10,
                  currency: 'USD',
                  description: 'Shipping'
                }
              ],
              shipping_address: {
                name: 'John Doe',
                line_1: '123 State Street',
                line_2: 'Apt. 34',
                line_3: '',
                city: 'Anytown',
                district: '',
                canton: '',
                state: 'NY',
                country: 'US',
                zip: '12345',
                phone_number: '12125559999',
                metadata: {
                  merchant_defined: true
                }
              },
              tax_percent: 0,
              upstream_id: 'GZC12345',
              email: 'johndoe@rapyd.net',
              metadata: {
                merchant_defined: true
              }
            };
            const result = await makeRequest('POST', '/v1/orders', body);
        
            console.log(result);
          } catch (error) {
            console.error('Error completing request', error);
          }
        }
        
    • PHP

      • <?php
        $path = $_SERVER['DOCUMENT_ROOT'];
        $path .= "/<path-to-your-utility-file>/utilities.php";
        include($path);
        
        $body = [
            "customer" =>  "cus_c697782cd18d3862e40e991fe4f0ca34",
            "currency" =>  "USD",
            "external_coupon_code" =>  "squeee",
            "items" =>  array(
                array(
                    "type" =>  "sku",
                    "currency" =>  "USD",
                    "amount" =>  200,
                    "quantity" =>  2,
                    "parent" =>  "sku_2cc9627661754e0a0b78397a62c9d9f2",
                    "description" =>  "Deluxe Gamer's Chair"
                ),
                array(
                    "type" => "shipping",
                    "amount" =>  10,
                    "currency" =>  "USD",
                    "description" =>  "Shipping"
                )
            ),
            "shipping_address" => array(
                "name" => "John Doe",
                "line_1" => "123 State Street",
                "line_2" => "Apt. 34",
                "line_3" => "",
                "city" => "Anytown",
                "district" => "",
                "canton" => "",
                "state" => "NY",
                "country" => "US",
                "zip" => "12345",
                "phone_number" => "12125559999",
                "metadata" => array(
                    "merchant_defined" => true
                )
            )
            "tax_percent" =>  0,
            "upstream_id" =>  "GZC12345",
            "email" =>  "johndoe@rapyd.net",
            "metadata" =>  array(
                "merchant_defined" => true
            ),
        ];
        
        try {
            $object = make_request('post', '/v1/orders', $body);
            var_dump($object);
        } catch(Exception $e) {
            echo "Error =>  $e";
        }
        ?>
    • Python

      • from pprint import pprint
        
        from utilities import make_request
        
        order = {
            "customer": "cus_c697782cd18d3862e40e991fe4f0ca34",
            "currency": "USD",
            "external_coupon_code": "squeee",
            "items": [
                {
                    "type": "sku",
                    "currency": "USD",
                    "amount": 200,
                    "quantity": 2,
                    "parent": "sku_2cc9627661754e0a0b78397a62c9d9f2",
                    "description": "Deluxe Gamer's Chair"
                },
                {
                    "type": "shipping",
                    "amount": 10,
                    "currency": "USD",
                    "description": "Shipping"
                }
            ],
            "shipping_address": {
                "name": "John Doe",
                "line_1": "123 State Street",
                "line_2": "Apt. 34",
                "line_3": "",
                "city": "Anytown",
                "district": "",
                "canton": "",
                "state": "NY",
                "country": "US",
                "zip": "12345",
                "phone_number": "12125559999",
                "metadata": {
                    "merchant_defined": True
                }
            },
            "tax_percent": 0,
            "upstream_id": "GZC12345",
            "email": "johndoe@rapyd.net",
            "metadata": {
                "merchant_defined": True
            }
        }
        result = make_request(method='post', path='/v1/orders', body=order)
        pprint(result)
        
  • /v1/orders

  • Create an Order

  • curl -X post
    https://sandboxapi.rapyd.net/v1/orders
    -H 'access_key: your-access-key-here'
    -H 'Content-Type: application/json'
    -H 'idempotency: your-idempotency-parameter-here'
    -H 'salt: your-random-string-here'
    -H 'signature: your-calculated-signature-here'
    -H 'timestamp: your-unix-timestamp-here'
    -d '{
        "customer": "cus_c62e8561f1f9217676819dce60accc08",
        "currency": "usd",
        "coupon": "coupon_aa742b3f19b5b096deebe0bdb1892725",
        "items": [
            {
                "type": "sku",
                "currency": "usd",
                "amount": 200.00,
                "quantity": 2,
                "parent": "sku_e19d99d1dfd757e47fbf36f24d8729dd",
                "description": "Deluxe Gamer's Chair"
            },
            {
                "type": "shipping",
                "amount": 10.00,
                "currency": "usd",
                "description": "Shipping"
            }
        ],
        "shipping_address": {
            "name": "John Doe",
            "line_1": "123 State Street",
            "line_2": "Apt. 34",
            "line_3": "",
            "city": "Anytown",
            "district": "",
            "canton": "",
            "state": "NY",
            "country": "US",
            "zip": "12345",
            "phone_number": "12125559999",
            "metadata": {
                "merchant_defined": true
            }
        },
        "tax_percent": 0,
        "upstream_id": "GZC12345",
        "email": "johndoe@rapyd.net",
        "metadata": {
            "merchant_defined": true
        }
    }
    '
    
  • {
        "status": {
            "error_code": "",
            "status": "SUCCESS",
            "message": "",
            "response_code": "",
            "operation_id": "58bfd57e-070f-4ed5-8a45-6b5d001def8e"
        },
        "data": {
            "id": "order_3e4c18a159524d46d7d1bf77e0df7a83",
            "amount": 409,
            "amount_returned": 0,
            "payment": null,
            "created": 1648454284,
            "customer": "cus_c62e8561f1f9217676819dce60accc08",
            "currency": "USD",
            "email": "johndoe@rapyd.net",
            "external_coupon_code": "coupon_aa742b3f19b5b096deebe0bdb1892725",
            "items": [
                {
                    "amount": 200,
                    "currency": "USD",
                    "description": "Deluxe Gamer's Chair",
                    "parent": "sku_e19d99d1dfd757e47fbf36f24d8729dd",
                    "quantity": 2,
                    "type": "sku"
                },
                {
                    "amount": 10,
                    "currency": "USD",
                    "description": "Shipping",
                    "parent": "",
                    "quantity": 1,
                    "type": "shipping"
                },
                {
                    "amount": -1,
                    "currency": "USD",
                    "description": "Applied discount by coupon coupon_aa742b3f19b5b096deebe0bdb1892725",
                    "parent": "coupon_aa742b3f19b5b096deebe0bdb1892725",
                    "quantity": 0,
                    "type": "discount"
                }
            ],
            "metadata": {
                "merchant_defined": true
            },
            "returns": [],
            "shipping_address": {
                "id": "address_69d0a4c0b0a46699cd9ce32a484da574",
                "name": "John Doe",
                "line_1": "",
                "line_2": "",
                "line_3": "",
                "city": "Anytown",
                "state": "NY",
                "country": "US",
                "zip": "12345",
                "phone_number": "12125559999",
                "metadata": {
                    "merchant_defined": true
                },
                "canton": "",
                "district": "",
                "created_at": 1648454284
            },
            "status": "created",
            "status_transitions": {
                "canceled": 0,
                "fulfilled": 0,
                "paid": 0,
                "returned": 0,
                "pending": 0,
                "partial": 0
            },
            "updated": 1648454284,
            "upstream_id": "GZC12345",
            "tax_percent": 0
        }
    }