While blockchain is booming, it is still very difficult for programmers to support digital currency receipts on websites. Both Bitcoin and EOS require the installation of full node software to achieve stable inquiry and payment services. However, all current blockchain nodes consume a lot of hard disk space and system resources, and it is not cost-effective to invest just for the purpose of receiving digital currency.

Here is a collection plug-in.

Advantages:

  1. There is no need to rely on external libraries because it is written in go.
  2. No external database is required, the default database is SQlite3, skilled workers can modify their own support for mysql and PostGRE.
  3. Developers can use HTTP requests to create payment channels and query payment status.
  4. There is push after receiving payment, which is convenient for writing business code.
  5. You don’t need to install complex bitcoin full node, Ethereum full node, EOS full node to collect money.
  6. Small size

Steps:

1. Create a Mixin Messenger account.

Visit Mixin. one/messenger to download the corresponding mobile App.

Users in mainland China can visit a.app.qq.com/o/simple.js… download

2. Activate the developer account

Log in to developer.mixin.one and swipe the App to log in

This tutorial is useful for new developers.

Clone, build, run

git clone https://github.com/myrual/mixin-network-snapshot-golang
cd mixin-network-snapshot-golang
Copy the code
  1. Edit some configuration information
const (
	userid      = "3c5fd587-5ac3-4fb6-b294-423ba3473f7d"
	sessionid   = "42848ded-0ffd-45eb-9b46-094d5542ee01"
	private_key = `-----BEGIN RSA PRIVATE KEY----- MIICXAIBAAKBgQDACTrT4uaB9el9qe0MUOsFrm8kpaDI9PowauMB1Ha25mpfL+5h MFqISLS5z2P89nAsXBg+KyQ2gAVA6rBwW/ZqOc1PKiJhhLBS80nzo3ayfv7OlzNG IxMyqD5izCCtPixnqpuTePoPWq4CNZlxop0VYklsWEfU0U0qqMBgmtqYfQIDAQAB AoGAR8crZed5oTn5fC73m5LjRcxdXqVJ49MtcMuC7jwr41FckRepUkpwjGAgrRMH nJXAd9Q0e4hEkNppHEqciGLXR1dQfZnaM1Gnv7mD3oSgHaH+4qAMnNOCpvwW4Eu3 yp9b1UGj9SvM3D2BrpA+MGf0E/yEJzpRcT956W6SPYYSegECQQDm4uTK+teoxr1Z agJZuCta+IhMzpxIWMob+JN/Huf7OnRcIa9JpXngg4tHOUWmZCDQdqeJMpaQc8SQ 44hba015AkEA1OyJswNIhdmvVp5P1zgREVVRK6JloYwmAtj+Qo4pWJ117LqH4w+b 491r4AeLEGh8VrZ4k6Hp+Cm783S2jTAWJQJARbWdlHdV45xVkQiDuyjy1h2RsXb0 EpfUNcvAZLIlImIMvcBh1x+CA7pTs+Zj1BAJJEee37qJYQXDBGfeRJPKKQJAVG+c x42Ew/eoTZwoIzvLoOkJcFlNHjwaksSER9ZiVQ7URdVOr99vvXQAJG45Wn9k12oy 9LCfvNan/wqIngK0tQJBAL1Wc02seEbMeWyt5jycJEhn6G8F18s9S1v0GXb4U/7/ 6Y87P3TmDLcEuCXkrbZQaCX7jVLu0BkDw8To58TWjh0= -----END RSA PRIVATE KEY-----`
	ADMIN_MessengerID = ""//this is your mixin messenger id, you can find your id in contact page.
)
Copy the code
  1. compile
go build mixin_snap.go
Copy the code
  1. run
./mixin_snap
Copy the code
  1. A test.db sqlite3 file is generated in the same directory as the database.

How to use

How do I accept payment in digital currency

In order to accept Bitcoin, EOS payments, the developer needs to access localhost:8080/ Payment using the HTTP POST method, with the parameters in the body. The body should have a unique identifier string, a callback to the URL, and a callback to the expiration date. A unique identifier string can be any character, as can a UUID. After receiving the payment from the user, the application accesses the native Callback URL using the HTTP POST method. The fallback mechanism has an expiration date, after which the fallback mechanism stops. If the fallback period parameter is 60, the fallback mechanism will expire after 60 minutes. The curl example

curl -d '{"reqid":"value8", "callback":":9090/", "expiredafter":60}' -H "Content-Type: Application/json "127.0.0.1:8080 / paymentCopy the code

This instructs the program to create a payment address for Value8. If it receives a payment from the user within 60 minutes, the program will call localhost:9090/ in HTTP POST mode, with parameters.

The result of this instruction is

{"Reqid":"value8"."Payment_methods": [{"Name":"XLM"."PaymentAddress":""."PaymentAccount":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y"."PaymentMemo":"3f8db42022b5bc32"}, {"Name":"EOS"."PaymentAddress":""."PaymentAccount":"eoswithmixin"."PaymentMemo":"302c37ebff05ccf09dd7296053d1924a"}, {"Name":"ETH"."PaymentAddress":"0x365DA43BC7B22CD4334c3f35eD189C8357D4bEd6"."PaymentAccount":""."PaymentMemo":""}]."Payment_records":null."Balance":null}
Copy the code

The results in Payment_methods are for the customer, and this example has three payment methods.

There are two styles of payment:

  1. Bitcoin/Ethereum: PaymentAddress is not empty, PaymentAccount and PaymentMemo are empty. In this case, you only need to show the user the asset name Ethereum and PaymentAddress, and the customer only needs to pay to the Ethereum address.
  2. EOS/ Planet: PaymentAddress is empty, both PaymentAccount and PaymentMemo have contents. In this case, you need to show the user the name of the asset, the receiving account and the receiving remarks, and seriously remind the user to fill in the receiving account and the receiving remarks at the same time. If the customer forgets to fill in the remarks, it will not be able to receive the account, and there is no refund.

Check receipt status

You can query payment status and records by accessing localhost:8080/ Payment with the parameter reqID.

Example:

curl -X GET 'http://localhost:8080/payment? reqid=value8'Copy the code

If the customer hasn’t paid, this is what happens

{"Reqid":"value8"."Payment_methods": [{"Name":"XLM"."PaymentAddress":""."PaymentAccount":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y"."PaymentMemo":"3f8db42022b5bc32"}, {"Name":"EOS"."PaymentAddress":""."PaymentAccount":"eoswithmixin"."PaymentMemo":"302c37ebff05ccf09dd7296053d1924a"}, {"Name":"ETH"."PaymentAddress":"0x365DA43BC7B22CD4334c3f35eD189C8357D4bEd6"."PaymentAccount":""."PaymentMemo":""}]."Payment_records":null."Balance":null}
Copy the code

Paymnet_records is empty

If the customer has already paid, this is what happens.

{"Reqid":"value8"."Payment_methods": [{"Name":"XLM"."PaymentAddress":""."PaymentAccount":"GD77JOIFC622O5HXU446VIKGR5A5HMSTAUKO2FSN5CIVWPHXDBGIAG7Y"."PaymentMemo":"3f8db42022b5bc32"}, {"Name":"EOS"."PaymentAddress":""."PaymentAccount":"eoswithmixin"."PaymentMemo":"302c37ebff05ccf09dd7296053d1924a"}, {"Name":"ETH"."PaymentAddress":"0x365DA43BC7B22CD4334c3f35eD189C8357D4bEd6"."PaymentAccount":""."PaymentMemo":""}]."Payment_records": [{"Amount":"0.1"."AssetId":""."created_at":"The 2019-06-20 T02:00:39. 650472961 z"."snapshot_id":"570233aa-3c91-45cd-a6ec-0e9724165300"}, {"Amount":"0.01"."AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d"."created_at":"The 2019-06-20 T02:33:50. 152539755 z"."snapshot_id":"88859d4d-5bee-4fb5-aef6-ac01dc3a43c6"}, {"Amount":"0.01"."AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d"."created_at":"The 2019-06-20 T02:37:05. 870885973 z"."snapshot_id":"6530f455-3238-491a-a9c5-bbcb52bcc306"}, {"Amount":"0.001"."AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d"."created_at":"The 2019-06-20 T02:40:53. 251365044 z"."snapshot_id":"f2c8a751-3d30-472e-bf76-924787f341b9"}, {"Amount":"0.001"."AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d"."created_at":"The 2019-06-20 T02:59:28. 854380284 z"."snapshot_id":"3ebfd5a3-bd29-4e32-bd06-2506bee3da99"}, {"Amount":"0.122"."AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d"."created_at":"The 2019-06-20 T03:00:17. 249302744 z"."snapshot_id":"0bfe6f6b-1ff8-4144-9786-52d6a6459b19"}]."Balance":null}
Copy the code

Payment_records has payment information. One of the payment details is as follows

{"Amount":"0.01"."AssetId":"6cfe566e-4aad-470b-8c9a-2fd35b49c68d"."created_at":"The 2019-06-20 T02:37:05. 870885973 z"."snapshot_id":"6530f455-3238-491a-a9c5-bbcb52bcc306"}
Copy the code

This is a payment from the customer:

  • The number of 0.01
  • Asset ID 6CFE566E-4AAD-470B-8C9A-2FD35B49C68D is the EOS mainnet token
  • Pay generated at UTC 2019-06-20T02:37:05.870885973
  • You can check the transaction in your browser and check it. One /snapshots/6…

Back off the URL

Upon receipt of the user’s payment within the validity period, the program accesses the local callback URL.

"Http://127.0.0.1" + callbackurlCopy the code

The HTTP access method is POST, and the parameters are in the body, as shown in the following example

{"Reqid":"value8"."Callbackurl":": 9090 /"."Paymentrecord": {"Amount":"0.01"."AssetId":"56e63c06-b506-4ec5-885a-4a5ac17b83c1"."created_at":"The 2019-06-20 T07:33:06. 445471337 z"."snapshot_id":"a6603374-509b-4015-a192-c63bfa8def5f"}}
Copy the code

Do all assets belong to the developer?

  1. All assets will be automatically transferred to your designated account, free of charge, in one second.
  2. After the program restarts or exits unexpectedly, you can manually instruct the program to transfer all assets to the account you specify.

Example:

The curl -x POST - H "content-type: application/json" 127.0.0.1:8080 / moneygohomeCopy the code

The results are as follows

total 20 account will send all balance to admin
Copy the code

Confirmation time of payment

  1. EOS: 3 minutes
  2. Stellar: 2 minutes
  3. Bitcoins/USDT: 60 minutes
  4. Litecoin/Ethererum/DOGE: 120 minutes

What is confirmation time? Most digital currencies take a little time from the time a user initiates a transfer request to the time the recipient confirms that the payment cannot be rolled back.

Why is it so long? This is the Mixin Network configuration itself, you can not change now.

What assets are supported

In theory, everything supported by Mixin Network is acceptable. Now supports BTC, USDT, BCH, Ethereum and ERC20, ETC, EOS and Tokens issued on EOS, DASH, Litecoin, Doge, Horizen, MGD, NEM, XRP, XLM, Tron and tron TRC10, Zcash.

The current code base supports assets by default

Currently the default supported assets in the code are EOS and stars, as they can both be confirmed in 3 minutes.

To support more coins, place the corresponding asset variable in default_ASset_ID_group.

const (
	BTC_ASSET_ID  = "c6d0c728-2624-429b-8e0d-d9d19b6592fa"
	EOS_ASSET_ID  = "6cfe566e-4aad-470b-8c9a-2fd35b49c68d"
	USDT_ASSET_ID = "815b0b1a-2764-3736-8faa-42d694fa620a"
	ETC_ASSET_ID  = "2204c1ee-0ea2-4add-bb9a-b3719cfff93a"
	XRP_ASSET_ID  = "23dfb5a5-5d7b-48b6-905f-3970e3176e27"
	XEM_ASSET_ID  = "27921032-f73e-434e-955f-43d55672ee31"
	ETH_ASSET_ID  = "43d61dcd-e413-450d-80b8-101d5e903357"
	DASH_ASSET_ID = "6472e7e3-75fd-48b6-b1dc-28d294ee1476"
	DOGE_ASSET_ID = "6770a1e5-6086-44d5-b60f-545f9d9e8ffd"
	LTC_ASSET_ID  = "76c802a2-7c88-447f-a93e-c29c9e5dd9c8"
	SIA_ASSET_ID  = "990c4c29-57e9-48f6-9819-7d986ea44985"
	ZEN_ASSET_ID  = "a2c5d22b-62a2-4c13-b3f0-013290dbac60"
	ZEC_ASSET_ID  = "c996abc9-d94e-4494-b1cf-2a3fd3ac5714"
	BCH_ASSET_ID  = "fd11b6e3-0b87-41f1-a41f-f0e9b49e5bf0"
	XIN_ASSET_ID  = "c94ac88f-4671-3976-b60a-09064f1811e8"
	CNB_ASSET_ID  = "965e5c6e-434c-3fa9-b780-c50f43cd955c"
	XLM_ASSET_ID  = "56e63c06-b506-4ec5-885a-4a5ac17b83c1"
	TRON_ASSET_ID = "25dabac5-056a-48ff-b9f9-f67395dc407c"......) . .// to support more asset, just add them in the following array
	default_asset_id_group := []string{XLM_ASSET_ID, EOS_ASSET_ID}
Copy the code

Next development tasks:

  1. All assets can be automatically withdrawn to the developer’s own cold wallet, rather than just transferred to the Mixin Messenger account.
  2. Assets received can be automatically converted into USDT or Bitcoin via decentralized exchanges.
  3. Mixin Messenger user payments are supported.
  4. You can provide the dollar price of the asset.

Mixin collection plug-in Q&A group