Skip to main content

Instant Exchange

Our MixPay API has an instant exchange feature. It allows users to have an amazingly smooth experience accepting whatever crypto they’ve set their eyes on.

Introduction

Our MixPay API has an instant exchange feature, allowing users to have an amazingly smooth experience accepting whatever crypto they’ve set their eyes on.

Here is an overview of the integration process:

  1. Use our assets API to construct a user view;
  2. When a user makes an order, call the create payment API, using a trace ID;
  3. When getting the result, perform actions for the user to pay;
  4. When payment finish, call the get payment result API, using the same trace ID.

Let's start with a detailed guide.

Step 1 - Use the assets API to construct a view

Use the following three API to

  • Payment Assets - Used to let payers choose which payment cryptocurrency they want to pay;
  • Quote Assets - Used when you calculate the total payment amount and show it to the user;
  • Settlement Assets - Used when you are setting the payee settlement type.

Step 2 - Create a payment

  1. There is no need to register MixPay to use MixPay API. You can just use MixPay API with your preferred languages. MixPay API click here.

  2. You can use this bot(7000101422) to get the Mixin UUID; send the Mixin ID in the chat window to the bot. It's simple, and no programming is required.

  3. Also, if the user UUID you want to acquire is a MixPay user, you can get this UUID via getting Mixin UUID API.

  4. You can use On-chain Payments and Create Payments API to create a payment. The specific parameters are as below. And you can place the payment link on a button.

When creating a payment, you need to pass a traceId; with traceId, you can get the payment result using this API - Payments Results.

The traceId you can generate randomly; the format is UUID; you need to create this UUID, and then store it in your orders database table for future to use, for example, checking the crypto payment result.

If you are using Golang, you can generate the UUID as below:

package main

import (
"fmt"
"github.com/google/uuid"
)

func main() {
id := uuid.New()
fmt.Println(id.String())
}
info

Tip: Please note that** traceId **has to be unique in your system; it's like order id but in UUID format.

Assuming the traceId is dd9c3e04-a5d2-11ec-b909-0242ac120002 generated by the sample code, the full sample request and parameters are below.

Endpoint URL

https://api.mixpay.me/v1/payments

Example request - Create Mixin Payment

curl -i -X POST https://api.mixpay.me/v1/payments \
-d "payeeId"="a0d7791408776b47eb1dd3f94ed15d6a" \
-d "paymentAssetId"="c6d0c728-2624-429b-8e0d-d9d19b6592fa" \
-d "settlementAssetId"="c6d0c728-2624-429b-8e0d-d9d19b6592fa" \
-d "quoteAssetId"="usd" \
-d "traceId"="dd9c3e04-a5d2-11ec-b909-0242ac120002" \
-d "quoteAmount"="0.1" \
-d "remark"="xxxxxx"

Example request - Create On Chain Payment

curl -i -X POST https://api.mixpay.me/v1/payments \
-d "payeeId"="a0d7791408776b47eb1dd3f94ed15d6a" \
-d "paymentAssetId"="c6d0c728-2624-429b-8e0d-d9d19b6592fa" \
-d "settlementAssetId"="c6d0c728-2624-429b-8e0d-d9d19b6592fa" \
-d "quoteAssetId"="usd" \
-d "traceId"="dd9c3e04-a5d2-11ec-b909-0242ac120002" \
-d "quoteAmount"="0.1" \
-d "remark"="xxxxxx" \
-d "isChain"="1"

Parameters

ParamOptionalTypeDescription
payeeId*requiredStringthree settlement modes are supported, normal user, robot, and multisig group, so it is usually the Mixin UUID of a normal user or robot. You can also specify the multisigId of a sub-account.
traceId*requiredStringUUID, used to prevent double payment.
paymentAssetId*requiredStringassetId of payment cryptocurrency. You can see the supported asset id in Payment Assets.
settlementAssetId*requiredStringassetId of settlement cryptocurrency. Settlement assets you prefer. If left blank, the payee will receive the cryptocurrency the user pays for. For more options, see here.
quoteAssetId*requiredStringassetId of quote cryptocurrency. For more options, see here.
quoteAmount*requiredNumericAmount of cryptocurrency received; if left blank, the user can enter manually.
isChainoptionalBooleanWhether is on-chain payment or not. true is using on-chain payment, false means pay using Mixin App.
remarkoptionalStringPayment remark viewable by the payee.

Response

{
"code": 0,
"success": true,
"message": "",
"data": {
"isChain": false,
"expire": 1648191480,// Payment expiration time
"seconds": 900,
"payeeId": "834c17e1-1427-434a-a280-1b3cfee05111",
"traceId": "4f7b0b8c-5112-4c25-9cea-4281ebf0d2dd",// The trace id when the user pays, to get the result of payment. And trace for mixin.
"clientId": "640a555a-b554-4790-95ec-6c5675381035",
"paymentAssetId": "25dabac5-056a-48ff-b9f9-f67395dc407c",// Assets to be paid by payer. And asset for mixin
"settlementAssetId": "25dabac5-056a-48ff-b9f9-f67395dc407c",
"quoteAssetId": "25dabac5-056a-48ff-b9f9-f67395dc407c",
"paymentAmount": "4",// The amount of assets to be paid by payer. And amount for mixin
"quoteAmount": "4",
"estimatedSettlementAmount": "4",
"memo": "cGF5bWVudHw2NDBhNTU1YS1iNTU0LTQ3OTAtOTVlYy02YzU2NzUzODEwMzU=",// memo for mixin
"recipient": "3539c3ce-52c0-4b0b-9573-c035ecb98d48",// recipient for mixin
"settlementAssetSymbol": "TRX",
"paymentAssetSymbol": "TRX",
"quoteAssetSymbol": "TRX",
"destination": "",
"tag": ""
},
"timestampMs": 1648190580346
}

Step 3 - Perform actions for the user to pay

When you get the result of the Create Payments API, you can perform corresponding actions.

If it's a Mixin payment, you can use Mixin URL Schema to wake up Mixin Wallet to make a payment.

If it's an on-chain payment, in the JSON Response, there is a key call destination; this is the Address customer has to transfer the cryptocurrency. Note that if the payment assets are EOS, you can use the tag and destination from the API result.

Step 4 - Checking the payment results

Finally, use the payments-results API to loop query payments result; the parameter is the traceId you generated. And the response is the status of payment. The status has three parameters, unpaid failed and succeeded.

Q & A

You can contact Robin(Mixin ID: 26930) directly if you have any further questions.