Create Order

When the customer clicks the 'Pay with Crypto' button, he/she is going to the Crypto payment page payment_url. Create Order API does two things.

Create Order API will do two things.

  • You need to provide basic payment info to display, including price_amount, title, description. e.g. 9.9 USD for the monthly membership.

  • You will have a payment_url page to direct the user. The page will contain the basic payment info.

  • You need to provide the success_url (when the payment succeeds, the user will be redirected there), and callback_url (we will tell the callback_url when the payments succeed).

This is the ONLY API needed for your website.


Definition

POST https://api.mugglepay.com/v1/orders

Body Params

ParamTypeRequiredDescription

merchant_order_id

string

Merchant's custom order ID. We recommend using the orderID from your application. It's a unique order ID for your reference.

price_amount

double

Yes

The price set by the merchant. Example: 9.99

price_currency

string

Yes

The currency in which you wish to price your merchandise; used to define price parameter. Example: USD, CNY. Default USD

pay_currency

string

Only use this field if you have the payment gateway enabled, and it will select the payment gateway. e.g. ETH, USDT, USDC

title

string

Max 200 characters. Example: product title (Apple iPhone X), order id (OnlineStore Order #4321), cart id (Cart #00003552).

description

string

More details about this order. Max 800 characters. It can be cart items, product details or other information. Example: 1 x Apple iPhone X, 1 x Apple MacBook Air.

callback_url

string

Send an automated message to Merchant URL when order status is changed. For example, when the user finishes the payment, we will make a request with your token to callback_url. Example: http://onlinestore.com/payments/callback

cancel_url

string

Redirect to Merchant URL when the customer cancels the order. Example: http://onlinestore.com/cart

success_url

string

Redirect to Merchant URL after successful payment. Example: http://onlinestore.com/account/orders.

mobile

bool

Based on PC or Mobile Wap, we provide different links.

fast

bool

Return the payment url directly.

token

string

Your custom token to validate Payment Callback. If it's provided, we will add it to the request of Payment Callback. This token is generated by the merchants, which is different from API_TOKEN_GET_FROM_ADMIN_PORTAL (generated by MugglePay) in the headers.

Example

Request with Curl

The easiest way to try this API: Replace API_TOKEN_GET_FROM_ADMIN_PORTAL with the one from backend portal.

curl -X POST \
  https://api.mugglepay.com/v1/orders \
  -H 'content-type: application/json' \
  -H 'token: API_TOKEN_GET_FROM_ADMIN_PORTAL' \
  -d '{
  "merchant_order_id": 100388,
  "price_amount": 10,
  "price_currency": "USD"
}'

Request with NodeJS

var request = require("request");

var options = { method: 'POST',
  url: 'https://api.mugglepay.com/v1/orders',
  headers: { 
     'token': 'API_TOKEN_GET_FROM_ADMIN_PORTAL',
     'content-type': 'application/json' 
     },
  body: { 
     merchant_order_id: '503a854998-6230-4338-adb7',
     title: "Monthly Program x 1",
     description: "Gaming for your family",
     price_amount: 1,
     price_currency: 'USD',
     pay_currency: 'USDT_ARBI',
     callback_url: "https://ecards.com/api/success",
     cancel_url: "https://ecards.com/ecardstatus?status=cancel",
     success_url: "https://ecards.com/ecardstatus?status=success",
  },
  json: true 
};

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});

POST Body

{
  "merchant_order_id": "503a854998-6230-4338-adb7",
  "price_amount": 1.00,
  "price_currency": "USD",
  "title": "Monthly Program x 1",
  "description": "Game Pass Friends and Family, up to four players can enjoy Game Pass",
  "callback_url": "https://ecards.com/api/success",
  "cancel_url": "https://ecards.com/ecardstatus?status=cancel",
  "success_url": "https://ecards.com/ecardstatus?status=success",
  "token": "XI231SD02-SDFWE123D"
}

Result Format

200 OK

{
    "status": 201,
    "order": {
        "user_id": 32014,
        "merchant_order_id": "503a854998-6230-4338-adb7",
        "title": "Monthly Program x 1",
        "description": "Game Pass Friends and Family, up to four players can enjoy Game Pass",
        "callback_url": "https://ecards.com/api/success",
        "cancel_url": "https://ecards.com/ecardstatus?status=cancel",
        "success_url": "https://ecards.com/ecardstatus?status=success",
        "price_amount": 1,
        "price_currency": "USD",
        "pay_amount": 1,
        "pay_currency": "USD",
        "order_id": "94be2b2a-2905-4857-b701-b04e57e84593",
        "status": "NEW",
        "created_at": "2019-04-24T16:57:35.416Z",
        "updated_at": "2019-04-24T16:57:35.416Z"
    },
    "payment_url": "https://invoice.mugglepay.com/invoices?id=94be2b2a-2905-4857-b701-b04e57e84593"
}

Error Format

MugglePay Server will always return status 400. If API failed, it will return error_code and error as its object.

{
    "status": 400,
    "error_code": "PARAMETERS_MISSING",
    "error": "Missing parameters."
}

Notes

When the buyers create the order, they are redirected to payment_url, where they can see the payment amount and then pay with crypto.

Your received payments will be settled immediately if USD or stable currency is selected.

Last updated