Skip to content

SecurePay ​

Create a Standard SecurePay ​

Definition

shell
POST
https://api.nihaopay.com/v1.2/transactions/securepay

Request

shell
$ 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"
shell
$ 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

json
{
    "url": "https://openapi.alipay.com/gateway.do?app_id=2019031263534265"
}

json response example 2

json
{
    "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 ​

PropertyDescription
currency
Required
The 3-letter currency code. See Parameters Description for acceptable currencie.
amount
Conditional
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_amount
Conditional
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.
vendor
Required
Transaction vendor. Currently, acceptable vendors are unionpay, alipay, wechatpay, and PayPal paypal.
payment_source
Optional
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_name
Conditional
Payer's given name. Required when vendor=paypal and payment_source=crypto.
surname
Conditional
Payer's surname. Required when vendor=paypal and payment_source=crypto.
reference
Required
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.
items
Conditional
Order product item list, see Parameters Description.
ipn_url
Required
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_url
Required
URL the browser will be redirected to upon completing the transaction.
description
Optional
Arbitrary string that you can set to be displayed on the card charge.
note
Optional
Arbitrary string as note to self regarding the transaction.
terminal
Optional
Default: ONLINE
Specifies whether payment is submitted on desktop (ONLINE) or mobile (WAP).
timeout
Optional
Default: 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_wechat
Optional
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_format
Optional
Default: HTML
Specifies whether the returned data is in (JSON) format or (HTML) format.

JSON response (when response_format as JSON) ​

PropertyDescription
id
string
Transaction ID.
url
Optional
Redirect url, when the interface returns url, the caller can directly redirect to this url after getting the url.
orderId
Optional
PayPal Order Id, used when the merchant creates an order using the PayPal JavaScript SDK Reference code.
form
Optional
form form object, and url are mutually exclusive, when the url does not exist, the form object exists.
form.actionUrl
Required
The action attribute of the form form.
form.method
Required
The method attribute of the form form
form.target
Required
The target attribute of the form form
form.params
Required
The parameters of the form form, in map format, key is the parameter name, and value is the parameter value.

Synchronous HTML Response ​

  1. 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.

  1. Response in JSON format (when response_format as JSON)

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

shell
$ 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

shell
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 = 46072c81e3c6140d6bc92655196b247f

Asynchronous 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.

PropertyDescription
id
string
Transaction ID.
status
string
Transaction status. In SecurePay scenario, only success.
amount
int
The settlement amount uses foreign currency.
rmb_amount
int
Payment Renminbi Amount. Same with the Request, If the request is null, payment amount will be returned.
currency
string
The 3-letter currency code.
time
string
Timestamp of the transaction in UTC. Ex: 2015-01-01T01:01:00Z is Jan 1, 2015 1:01:00 UTC.
reference
string
AlphaNumeric string set in request to correspond transaction ID with your original transaction request.
note
string
If set in request, your transaction note to self. Else if not set, this will be null.
sys_reserve
json
NihaoPay system reservation, it's json string, See Parameters Description.
verify_sign
string
Signature value.

Generate a Payment QRcode ​

Definition

shell
POST
https://api.nihaopay.com/v1.2/transactions/qrcode

Request

shell
$ 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 ​

PropertyDescription
currency
Required
The 3-letter currency code. See Parameters Description for acceptable currencie.
amount
Conditional
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_amount
Conditional
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.
vendor
Required
Transaction vendor. Currently, acceptable vendors are unionpay and wechatpay.
reference
Required
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.
items
Conditional
Order product item list, see Parameters Description.
ipn_url
Required
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.
timeout
Optional
Default: 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.
description
Optional
Arbitrary string that you can set to be displayed on the card charge.
note
Optional
Arbitrary string as note to self regarding the transaction.

Response

json
{
    "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.

PropertyDescription
code_url
string
The string of QR code url.
id
string
Transaction ID.
amount
int
Amount of the transaction in the minor unit of the currency. For example, cents in USD.
currency
string
The 3-letter currency code.
timeout
int
Within the specified minutes, code url will time out. If you did not provide this, default value will be returned to you.
reference
string
AlphaNumeric string set in request to correspond transaction ID with your original transaction request.
time
string
Timestamp of the transaction in UTC. Ex: 2015-01-01T01:01:00Z is Jan 1, 2015 1:01:00 UTC.

In-App Payment ​

Definition

shell
POST
https://api.nihaopay.com/v1.2/transactions/apppay

Request

shell
$ 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 ​

PropertyDescription
currency
Required
The 3-letter currency code. See Parameters Description for acceptable currencie.
amount
Conditional
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_amount
Conditional
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.
reference
Required
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.
items
Conditional
Order product item list, see Parameters Description.
vendor
Required
Transaction vendor. Currently, acceptable vendors are alipay,wechatpay and unionpay.
app_id
Conditional
APPID approved by WeChat Open Plarform. Required when vendor = wechatpay
ipn_url
Required
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.
description
Optional
Arbitrary string that you can set to be displayed on the card charge.
note
Optional
Arbitrary string as note to self regarding the transaction.
timeout
Optional
Default: 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.
ostype
Required
Specifies whether the payment page should be displayed on an Android phone (ANDROID) or an iphone (IOS).

Response

json
{
    "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.

PropertyDescription
orderInfo
string
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.
redirectUrl
string
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

shell
POST
https://api.nihaopay.com/v1.2/transactions/aplus

Request

shell
$ 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"
PropertyDescription
currency
Required
The 3-letter currency code. See Parameters Description for acceptable currencie.
amount
Conditional
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_amount
Conditional
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.
reference
Required
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.
items
Conditional
Order product item list, see Parameters Description.
ipn_url
Required
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_url
Conditional
URL the browser will be redirected to upon completing the transaction, Required when terminal=ONLINE or terminal=WAP.
description
Optional
Arbitrary string that you can set to be displayed on the card charge.
note
Optional
Arbitrary string as note to self regarding the transaction.
terminal
Optional
Default: ONLINE
Specifies whether payment is submitted on desktop (ONLINE) or mobile (WAP) or mobile application (APP) or mini program(MICRO).
timeout
Optional
Default: 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.
ostype
Conditional
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.
wallet
Optional
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

json
{
    "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 ​

PropertyDescription
amount
int
Order amount.
timeout
int
Order timeout time(minutes).
currency
string
Order currency.
reference
string
Your transactions id.
id
string
Nihaopay transactions id.
time
string
Order create time.
redirectUrl
string
The payment URL that redirects users to a WAP or Web page in the browser.

WeChat Mini-Program Payment ​

shell
POST
https://api.nihaopay.com/v1.2/transactions/micropay

Please 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.

Mini Program Flow

Request

shell
$ 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 ​

PropertyDescription
currency
Required
The 3-letter currency code. See Parameters Description for acceptable currencie.
amount
Conditional
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_amount
Conditional
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.
reference
Required
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.
items
Conditional
Order product item list, see Parameters Description.
app_id
Required
WeChat Mini-Program APPID.
ipn_url
Required
Instant Payment Notification URL. See Instant Payment Notification.
client_ip
Required
Customer IP
open_id
Required
The openid for a WeChat user that mini programs obtained after a wx.login() call. For get openid in mini programs please see here.
description
Optional
Arbitrary string that you can set to be displayed on the card charge.
note
Optional
Arbitrary string as note to self regarding the transaction.
timeout
Optional
Default: 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

json
{
    "timeStamp": "1510341967363",
    "nonceStr": "a611bda03d544b9f941393c48c2e517f",
    "wechatPackage": "prepay_id=wx201711110326070ccf2a7f060678638664",
    "signType": "MD5",
    "paySign": "09E5BE5B9D93080E3B7DD05C8F41049E"
}

Response ​

PropertyDescription
timeStamp
string
Time Stamp
nonceStr
string
Random string
wechatPackage
string
Data package include prepay_id=****
signType
string
Signature type, default MD5
paySign
string
Signature

PayPal ACDC Order Capture ​

shell
POST
https://api.nihaopay.com/v1.2/transactions/paypal/capture/{transaction_id}

Request

shell
$ 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

json
{
    "paypal_order_id": "80J3567205747094K",
    "paypal_capture_id": "0CW443673C1190047",
    "id": "20251215131749104834",
    "status": "success"
}

Response ​

PropertyDescription
id
string
Original transaction id
paypal_order_id
string
PayPal order id
paypal_capture_id
string
PayPal transaction id
status
string
Request result, including: success success, failure failure
processor_response_code
string
Response code from PayPal or card org processor.

Last Updated - 01/16/2025