SecurePay
Create a Standard SecurePay
Definition
POST
https://api.nihaopay.com/v1.2/transactions/securepayRequest
$ curl https://api.nihaopay.com/v1.2/transactions/securepay \
-H "Authorization: Bearer <TOKEN>" \
-d rmb_amount=100 \
-d currency="USD" \
-d vendor="alipay" \
-d reference="20171023191505118594" \
-d items[0].name="T-Shirt Test" \
-d items[0].unitAmount=100 \
-d items[0].quantity=1 \
-d ipn_url="https://demo.nihaopay.com/ipn" \
-d callback_url="https://demo.nihaopay.com/callback"$ curl https://api.nihaopay.com/v1.2/transactions/securepay \
-H "Authorization: Bearer <TOKEN>" \
-d rmb_amount=100 \
-d currency="USD" \
-d vendor="wechatpay" \
-d reference="20171023191505118594" \
-d items[0].name="T-Shirt Test" \
-d items[0].unitAmount=100 \
-d items[0].quantity=1 \
-d ipn_url="https://demo.nihaopay.com/ipn" \
-d in_wechat="false" \
-d callback_url="https://demo.nihaopay.com/callback"json response example 1
{
"url": "https://openapi.alipay.com/gateway.do?app_id=2019031263534265"
}json response example 2
{
"form": {
"actionUrl": "https://www.nihaopay.com/",
"method": "POST",
"target": "_self",
"params": {
"bizType": "000201",
"backUrl": "https://bgw.nihaopay.com/payBackResp/44e4af32d6494c71aaafe2eaf6c05910",
"orderId": "u20230827102153QvCEZp",
"txnSubType": "01"
}
}
}SecurePay transactions will redirect users to the vendor’s payment page, where users can enter payment information. Upon successful transaction, users will be redirected to the callback URL. These redirects are accomplished through the use of a JavaScript enabled form.
Due to the nature of redirects and users being able to close their browsers before the redirect can happen, an instant payment notification (IPN) URL is used to provide transaction data.
A reference string is also required to keep track of transactions as the Transaction object will not respond directly to the request but rather in the asynchronous call to your IPN URL. When you receive the Transaction object, you will need to match the reference against your records in order to determine which transaction IDs correspond to which requests.
Request
| Property | Description |
|---|---|
currencyRequired | The 3-letter currency code. See Parameters Description for acceptable currencie. |
amountConditional | Amount as a positive integer of the minor unit of the currency. If amount is not null, it means the transaction uses foreign currency. See Parameters Description. |
rmb_amountConditional | Amount as a positive integer of the minor unit of the currency. Use this parameter to replace amount if merchant wish to price their product in RMB. If amount is used, rmb_amount should not be set. They are mutual exclusive. See Parameters Description. |
vendorRequired | Transaction vendor. Currently, acceptable vendors are unionpay, alipay, wechatpay, and PayPal paypal. |
payment_sourceOptional | PayPal payment source. Defaults to the PayPal wallet. Pass crypto for PayPal Crypto payments. Pass ACDC for PayPal card payments when the merchant creates an order using the PayPal JavaScript SDK Reference code. |
given_nameConditional | Payer's given name. Required when vendor=paypal and payment_source=crypto. |
surnameConditional | Payer's surname. Required when vendor=paypal and payment_source=crypto. |
referenceRequired | An alphanumeric string up to 30 characters that must be unique to each of your transactions. This allows you to keep track of transactions when data comes back through IPN and Callback URLs. See Parameters Description. |
itemsConditional | Order product item list, see Parameters Description. |
ipn_urlRequired | Instant Payment Notification URL. Called by the API to update you on transaction information. This is where the response goes to. See Instant Payment Notification. |
callback_urlRequired | URL the browser will be redirected to upon completing the transaction. |
descriptionOptional | Arbitrary string that you can set to be displayed on the card charge. |
noteOptional | Arbitrary string as note to self regarding the transaction. |
terminalOptionalDefault: ONLINE | Specifies whether payment is submitted on desktop (ONLINE) or mobile (WAP). |
timeoutOptionalDefault: 120 | Specifies amount of minutes card holders have before payment page times out. Once the page times out without a successful payment, the transaction is automatically closed. Acceptable values are 1 - 1440. |
in_wechatOptional | When the current payment scenario is WeChat built-in browser, pass true, otherwise pass false and it is valid only when vendor=wechatpay. when in_wechat=false,if you have enabled WeChat H5 payment,use WeChat H5 payment otherwise downgrade For scanning code,use JSAPI to pay when in_wechat=true. |
response_formatOptionalDefault: HTML | Specifies whether the returned data is in (JSON) format or (HTML) format. |
JSON response (when response_format as JSON)
| Property | Description |
|---|---|
idstring | Transaction ID. |
urlOptional | Redirect url, when the interface returns url, the caller can directly redirect to this url after getting the url. |
orderIdOptional | PayPal Order Id, used when the merchant creates an order using the PayPal JavaScript SDK Reference code. |
formOptional | form form object, and url are mutually exclusive, when the url does not exist, the form object exists. |
form.actionUrlRequired | The action attribute of the form form. |
form.methodRequired | The method attribute of the form form |
form.targetRequired | The target attribute of the form form |
form.paramsRequired | The parameters of the form form, in map format, key is the parameter name, and value is the parameter value. |
Synchronous HTML Response
- HTML format response
The API returns a synchronous message to the merchant. The message is a form that should be displayed in the browser. The form will submit automatically to the vendor's payment portal, redirecting the user to complete the transaction.
- Response in JSON format (when
response_formatasJSON)
The returned json data returns a form object or url (not both). If the url is returned, the caller can directly redirect to this url after getting the url. If the return is a form object, the caller needs to use the fields in the form object to construct a form form by itself, and write the form form to In the current webpage request, the page will jump to the payment page after submission.
PayPal Crypto Payment
PayPal Crypto uses the standard SecurePay endpoint. When creating an order, pass vendor=paypal, payment_source=crypto, given_name, and surname. Redirect the browser to the returned url so the buyer can complete payment on the PayPal Crypto page. Use the browser callback_url and server-side ipn_url to determine the payment result.
Request
$ curl https://api.nihaopay.com/v1.2/transactions/securepay \
-H "Authorization: Bearer <TOKEN>" \
-d amount=100 \
-d currency="USD" \
-d vendor="paypal" \
-d payment_source="crypto" \
-d given_name="Jane" \
-d surname="Doe" \
-d reference="paypal-crypto-001" \
-d ipn_url="https://merchant.example.com/payment-ipn" \
-d callback_url="https://merchant.example.com/payment-callback" \
-d response_format="JSON"Asynchronous Response
id = 20170519103602011338
amount = 2
currency = USD
rmb_amount = 12
reference = 20170519103456437807
sys_reserve = {"vendor_id":"4200000117201806013734875340"}
status = success
time = 2017-05-19T10:36:32Z
note = null
verify_sign = 46072c81e3c6140d6bc92655196b247fAsynchronous Response
After completion of a securepay, API will return a transaction object to callback_url using the GET method, returns to ipn_url using the POST method.
Transaction IDs can be used to retrieve details, request cancellations, and create refunds.
Whenever possible, transaction data should be recorded from the IPN URL instead of the callback URL.
| Property | Description |
|---|---|
idstring | Transaction ID. |
statusstring | Transaction status. In SecurePay scenario, only success. |
amountint | The settlement amount uses foreign currency. |
rmb_amountint | Payment Renminbi Amount. Same with the Request, If the request is null, payment amount will be returned. |
currencystring | The 3-letter currency code. |
timestring | Timestamp of the transaction in UTC. Ex: 2015-01-01T01:01:00Z is Jan 1, 2015 1:01:00 UTC. |
referencestring | AlphaNumeric string set in request to correspond transaction ID with your original transaction request. |
notestring | If set in request, your transaction note to self. Else if not set, this will be null. |
sys_reservejson | NihaoPay system reservation, it's json string, See Parameters Description. |
verify_sign string | Signature value. |
Generate a Payment QRcode
Definition
POST
https://api.nihaopay.com/v1.2/transactions/qrcodeRequest
$ curl https://api.nihaopay.com/v1.2/transactions/qrcode \
-H "Authorization: Bearer <TOKEN>" \
-d amount=100 \
-d vendor="wechatpay" \
-d currency="USD" \
-d reference="jkh25jh1348fd89sg" \
-d ipn_url="http://website.com/ipn"Merchant's backend system requests payment QRcode API in order to generate an advance transaction and gets code_url. Merchant's backend creates a QR Code based on code_url which can be displayed on website or printed on the checkout bill. The cardholder opens "Scan" in WeChat or UnionPay QuickPass, scans the QR Code, enters his or her payment password and completes the transaction.
Upon transaction completion, the API will return asynchronous message to the IPN URL. Merchant can request Look up a transaction if no message is received.
The asynchronous message returned to IPN URL is the same with SecurePay.
Request
| Property | Description |
|---|---|
currencyRequired | The 3-letter currency code. See Parameters Description for acceptable currencie. |
amountConditional | Amount as a positive integer of the minor unit of the currency. If amount is not null, it means the transaction uses foreign currency. See Parameters Description. |
rmb_amountConditional | Amount as a positive integer of the minor unit of the currency. Use this parameter to replace amount if merchant wish to price their product in RMB. If amount is used, rmb_amount should not be set. They are mutual exclusive. See Parameters Description. |
vendorRequired | Transaction vendor. Currently, acceptable vendors are unionpay and wechatpay. |
referenceRequired | An alphanumeric string up to 30 characters that must be unique to each of your transactions. This allows you to keep track of transactions when data comes back through IPN and Callback URLs. |
itemsConditional | Order product item list, see Parameters Description. |
ipn_urlRequired | Instant Payment Notification URL. Called by the API to update you on transaction information. This is where the response goes to. See Instant Payment Notification. |
timeoutOptionalDefault: 120 | Specifies amount of minutes card holders have before payment page times out. Once the page times out without a successful payment, the transaction is automatically cancelled. Acceptable values are 1 - 1440. |
descriptionOptional | Arbitrary string that you can set to be displayed on the card charge. |
noteOptional | Arbitrary string as note to self regarding the transaction. |
Response
{
"id": "20160829075820003759",
"code_url": "weixin://wxpay/bizpayurl?pr=1dVyJZF",
"timeout": 90,
"amount": 100,
"currency": "USD",
"reference": "jkh25jh1348fd89sg",
"time": "2017-05-19T09:38:28Z"
}Response
Returns a QRcode object.
| Property | Description |
|---|---|
code_urlstring | The string of QR code url. |
idstring | Transaction ID. |
amountint | Amount of the transaction in the minor unit of the currency. For example, cents in USD. |
currencystring | The 3-letter currency code. |
timeoutint | Within the specified minutes, code url will time out. If you did not provide this, default value will be returned to you. |
referencestring | AlphaNumeric string set in request to correspond transaction ID with your original transaction request. |
timestring | Timestamp of the transaction in UTC. Ex: 2015-01-01T01:01:00Z is Jan 1, 2015 1:01:00 UTC. |
In-App Payment
Definition
POST
https://api.nihaopay.com/v1.2/transactions/apppayRequest
$ curl https://api.nihaopay.com/v1.2/transactions/apppay \
-H "Authorization: Bearer <TOKEN>" \
-d amount=100 \
-d currency="USD" \
-d vendor="alipay" \
-d reference="alipay20170503000300" \
-d ipn_url="http://website.com/ipn"For more information about In-App payment, see NihaoPay IOS demo or Andriod demo
Request
| Property | Description |
|---|---|
currencyRequired | The 3-letter currency code. See Parameters Description for acceptable currencie. |
amountConditional | Amount as a positive integer of the minor unit of the currency. If amount is not null, it means the transaction uses foreign currency. See Parameters Description. |
rmb_amountConditional | Amount as a positive integer of the minor unit of the currency. Use this parameter to replace amount if merchant wish to price their product in RMB. If amount is used, rmb_amount should not be set. They are mutual exclusive. See Parameters Description. |
referenceRequired | An alphanumeric string up to 30 characters that must be unique to each of your transactions. This allows you to keep track of transactions when data comes back through IPN and Callback URLs. |
itemsConditional | Order product item list, see Parameters Description. |
vendorRequired | Transaction vendor. Currently, acceptable vendors are alipay,wechatpay and unionpay. |
app_idConditional | APPID approved by WeChat Open Plarform. Required when vendor = wechatpay |
ipn_urlRequired | Instant Payment Notification URL. Called by the API to update you on transaction information. This is where the response goes to. See Instant Payment Notification. |
descriptionOptional | Arbitrary string that you can set to be displayed on the card charge. |
noteOptional | Arbitrary string as note to self regarding the transaction. |
timeoutOptionalDefault: 120 | Specifies amount of minutes card holders have before payment page times out. Once the page times out without a successful payment, the transaction is automatically cancelled. Acceptable values are 1 - 1440. |
ostypeRequired | Specifies whether the payment page should be displayed on an Android phone (ANDROID) or an iphone (IOS). |
Response
{
"orderInfo": "orderinfo string.....",
"redirectUrl": "https://wallet.com/xxx?xxx=xx....."
}Response
At the same time, only one of orderInfo and redirectUrl will be returned, and orderInfo is used first.
| Property | Description |
|---|---|
orderInfostring | Used to call the vendor SDK if not empty,. For more information, see NihaoPay IOS demo or Andriod demo. If you need WeChatPay In-app, please contact us for help. |
redirectUrlstring | The payment URL that redirects users to a WAP or Web page in the browser or in the WebView,see NihaoPay IOS demo or Andriod demo. |
Alipay A+
Wallet Support: AlipayHK,GCASH,DANA,KaKaoPay,TNG,TrueMoney
Definition
POST
https://api.nihaopay.com/v1.2/transactions/aplusRequest
$ curl https://api.nihaopay.com/v1.2/transactions/aplus \
-H "Authorization: Bearer <TOKEN>" \
-d amount=100 \
-d currency="USD" \
-d reference="alipay20170503000300" \
-d ipn_url="http://website.com/ipn" \
-d callback_url="http://website.com/callback"| Property | Description |
|---|---|
currencyRequired | The 3-letter currency code. See Parameters Description for acceptable currencie. |
amountConditional | Amount as a positive integer of the minor unit of the currency. If amount is not null, it means the transaction uses foreign currency. See Parameters Description. |
rmb_amountConditional | Amount as a positive integer of the minor unit of the currency. Use this parameter to replace amount if merchant wish to price their product in RMB. If amount is used, rmb_amount should not be set. They are mutual exclusive. See Parameters Description. |
referenceRequired | An alphanumeric string up to 30 characters that must be unique to each of your transactions. This allows you to keep track of transactions when data comes back through IPN and Callback URLs. See Parameters Description. |
itemsConditional | Order product item list, see Parameters Description. |
ipn_urlRequired | Instant Payment Notification URL. Called by the API to update you on transaction information. This is where the response goes to. See Instant Payment Notification. |
callback_urlConditional | URL the browser will be redirected to upon completing the transaction, Required when terminal=ONLINE or terminal=WAP. |
descriptionOptional | Arbitrary string that you can set to be displayed on the card charge. |
noteOptional | Arbitrary string as note to self regarding the transaction. |
terminalOptionalDefault: ONLINE | Specifies whether payment is submitted on desktop (ONLINE) or mobile (WAP) or mobile application (APP) or mini program(MICRO). |
timeoutOptionalDefault: 10 | Order timeout time, after NihaoPay receives the order request, if the customer fails to pay within the time specified by timeout (minutes), the order will be closed 1 - 10. |
ostypeConditional | Specifies whether the payment page should be displayed on an Android phone (ANDROID) or an iphone (IOS), Required when terminal=WAP or terminal=APP or terminal=MICRO. |
walletOptional | Default:CONNECT_WALLET, available options are ALIPAY_CN,ALIPAY_HK,TRUEMONEY,TNG,GCASH,DANA,KAKAOPAY,CONNECT_WALLET, CONNECT_WALLET means that all the available wallets will be displayed to the user, and the user can choose any wallet to pay. |
Response
{
"amount": 10,
"timeout": 10,
"currency": "USD",
"reference": "1657808342862",
"id": "20220714221903000379",
"time": "2022-07-14T22:19:03Z",
"redirectUrl": "https://alipay.com/connect.html?code=281666040098ZTL79hJiG7"
}Response
| Property | Description |
|---|---|
amountint | Order amount. |
timeoutint | Order timeout time(minutes). |
currencystring | Order currency. |
referencestring | Your transactions id. |
idstring | Nihaopay transactions id. |
timestring | Order create time. |
redirectUrlstring | The payment URL that redirects users to a WAP or Web page in the browser. |
WeChat Mini-Program Payment
POST
https://api.nihaopay.com/v1.2/transactions/micropayPlease send the WeChat Mini-program APPID to our support team before development.
Merchant can ask prePay request at the mini-program, and use the function wx.requestpayment() to call WeChatPay if the variable of request is generated successfully. NihaoPay will send IPN announcement to the IPN_url of merchant as long as the order has been placed successfully. Following figures illustrates the development process.

Request
$ curl https://api.nihaopay.com/v1.2/transactions/micropay \
-H "Authorization: Bearer <TOKEN>" \
-d amount=100 \
-d currency="USD" \
-d reference="wechatpay20171109000300" \
-d ipn_url="http://website.com/ipn" \
-d open_id="oSC6Tw7--mfjTCpIr-72rWloA8TU" \
-d client_ip="180.167.25.154"Request
| Property | Description |
|---|---|
currencyRequired | The 3-letter currency code. See Parameters Description for acceptable currencie. |
amountConditional | Amount as a positive integer of the minor unit of the currency. If amount is not null, it means the transaction uses foreign currency. See Parameters Description. |
rmb_amountConditional | Amount as a positive integer of the minor unit of the currency. Use this parameter to replace amount if merchant wish to price their product in RMB. If amount is used, rmb_amount should not be set. They are mutual exclusive. See Parameters Description. |
referenceRequired | An alphanumeric string up to 30 characters that must be unique to each of your transactions. This allows you to keep track of transactions when data comes back through IPN and Callback URLs. |
itemsConditional | Order product item list, see Parameters Description. |
app_idRequired | WeChat Mini-Program APPID. |
ipn_urlRequired | Instant Payment Notification URL. See Instant Payment Notification. |
client_ipRequired | Customer IP |
open_idRequired | The openid for a WeChat user that mini programs obtained after a wx.login() call. For get openid in mini programs please see here. |
descriptionOptional | Arbitrary string that you can set to be displayed on the card charge. |
noteOptional | Arbitrary string as note to self regarding the transaction. |
timeoutOptionalDefault: 120 | Specifies amount of minutes card holders have before payment page times out. Once the page times out without a successful payment, the transaction is automatically cancelled. Acceptable values are 1 - 1440. |
Success response
{
"timeStamp": "1510341967363",
"nonceStr": "a611bda03d544b9f941393c48c2e517f",
"wechatPackage": "prepay_id=wx201711110326070ccf2a7f060678638664",
"signType": "MD5",
"paySign": "09E5BE5B9D93080E3B7DD05C8F41049E"
}Response
| Property | Description |
|---|---|
timeStampstring | Time Stamp |
nonceStrstring | Random string |
wechatPackagestring | Data package include prepay_id=**** |
signTypestring | Signature type, default MD5 |
paySignstring | Signature |
PayPal ACDC Order Capture
POST
https://api.nihaopay.com/v1.2/transactions/paypal/capture/{transaction_id}Request
$ curl https://api.nihaopay.com/v1.2/transactions/paypal/capture/{transaction_id} \
-H "Authorization: Bearer <TOKEN>" \Merchants call this api to capture funds for PayPal ACDC orders, i.e., orders created using the PayPal Javascript SDK Reference code.
Request
transaction_id as URL parameter.
Success response
{
"paypal_order_id": "80J3567205747094K",
"paypal_capture_id": "0CW443673C1190047",
"id": "20251215131749104834",
"status": "success"
}Response
| Property | Description |
|---|---|
idstring | Original transaction id |
paypal_order_idstring | PayPal order id |
paypal_capture_idstring | PayPal transaction id |
statusstring | Request result, including: success success, failure failure |
processor_response_codestring | Response code from PayPal or card org processor. |
