Wechat Mini App Payment
Tips: Get your Wallet ID, User ID and API key via Latipay Merchant Portal > WALLETS > ACTION(on the right side of the corresponding wallet) > Settings > Integration parameters
Tips: Create a minimum amount product (e.g. $ 0.01 NZD/AUD) for testing.
TLTR
- use wx js api to login and get code in mini app
- use weixin api for getting openid with the code in your server
- send a request to latipay with the openid in your server
- use wx mini app payment api to make a payment in mini app
API Details
1 - Login in Mini App
https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html
Use wx js api to login and get code in mini app.
1 | wx.login({ |
2 - Get openId in your Backend
Use the code and weixin api to get the openid in your backend.
1 | GET https://api.weixin.qq.com/sns/jscode2session?appid={your mini APP ID}&secret={your mini app SECRET}&js_code={code here}&grant_type=authorization_code |
1 | { |
3 - Latipay Payment Interface
1 | POST https://api.latipay.net/v2/miniapppay |
- Parameters
| Name | Type | Description | Optional |
|---|---|---|---|
| user_id | String | The Latipay user account which is using for processing the transactions. | NO |
| wallet_id | String | The wallet ID that using for online transactions. | NO |
| amount | String | A decimal amount. | NO |
| notify_url | String | Merchant webserver’s URL that the payment result will send to. | NO |
| merchant_reference | String | A unique id identifying the order in Merchant’s system. |
NO |
| product_name | String | The name of the product or service being sold. | NO |
| app_id | String | Wechat mini app id | NO |
| open_id | String | Wechat mini app openid for current wechat user. | NO |
| signature | String | The SHA-256 HMAC API signature. |
NO |
Example
1 | { |
SHA-256 HMAC Signature Try your signature online
Rearrange all parameters alphabetically (except parameters with value of
nulloremptystring) and join them with&, and concat the value ofapi_keyin the end.
JS code example:
1 | Object.keys(data) |
Example
1 | message: amount=120.00&app_id=wx721398712681232&callback_url=https://merchantsite.com/confirm&ip=122.122.122.1&merchant_reference=dsi39ej430sks03&payment_method=alipay&product_name=Pinot Noir, Otago&return_url=https://merchantsite.com/checkout&user_id=U000334333&version=2.0&wallet_id=W00000001111222333 |
- Response
1 | { |
| Name | Type | Description |
|---|---|---|
| nonceStr | String | for wechat mini app payment |
| paySign | String | for wechat mini app payment |
| signType | String | for wechat mini app payment, should be ‘MD5’ |
| timeStamp | String | for wechat mini app payment |
| packageStr | String | for wechat mini app payment |
| order_id | String | A unique transaction identifier generated by Latipay. |
4 - Wechat mini app payment
This is the payment api in wechat document: https://developers.weixin.qq.com/miniprogram/dev/api/payment/wx.requestPayment.html
1 | wx.requestPayment({ |
Demo
In your wechat mini app:
- login
- create your own order and reqeust payment to Latipay
- make a payment
1 | //1. login |
In your backend:
- create your own order and get unique id
- get openid from wechat
- SHA-256 HMAC signature
- send request to latipay
- return to your mini app
1 | server.createPostAPI('/create_order_and_pay', function(req, res){ |