跳到主要内容

Integrate Binance Pay with your App

Binance Pay is a contactless, borderless and secure cryptocurrency payment technology designed by Binance. Binance Pay allows Binance customer to pay and get paid in crypto from your friends and family worldwide.

To begin, register your application with Binance Accounts, and get the SDK . For now, please contact us.

Signature Rule (For server engineer)

Binance Pay backend will check the signature against pay param, including "certSn", "merchantId", "noncestr", "prepayId" and "timeStamp".

AttributesTypeRequiredLimitationDescription
certSnstringY-API identity key issued by Binance payment system
merchantIdlongY-The merchant account id, issued when merchant been created at Binance.
noncestrstringYmust be 32 digitsA random string with 32 bytes, e.g. random ascii decimal within a-z and A-Z and loop 32 times to form a random string
prepayIdstringY-unique id generated by binance
timeStamplongYBinance pay only process request within 1sUnixTimestamp in millis that the requests send, guarantee the machine time is sync with the network

Signature generation logic is as below, please follow the parameters order. Use "=" connect field and value, use "&" to separate fields.

String payload = "certSn=317c110ebf7baf641e8f49ab6851331737dbe98541947c53b9dbba27f8c8414f" + "&" + "merchantId=98765987" + "&" + "noncestr=5K8264ILTKCH16CQ2502SI8ZNMTM67VS" + "&" + "prepayId=98765987" + "&"+ "timeStamp=1618302830073";
String signature = hex(hmac("sha512", payload, secretKey)).toUpperCase();

Integrate SDK for Android

Requirements

  • Android 4.1+
  • Support AndroidX

Import SDK

  1. Download binance_pay_sdk_v1.0.0.aar
  2. Add binance_pay_sdk_v1.0.0.aar into libs directory
  3. Add dependence for app module, just like this:
    android{
    repositories {
    flatDir {
    dirs 'libs'
    }
    }
    }
    dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation (name: 'binance_pay_sdk_v1.0.0', ext: 'aar')
  4. Sync project

Usage

1. Create BinancePayListener
class PayListener : BinancePayListener {
override fun onSuccess() {
// When the payment is successful, this will be called
}

override fun onCancel() {
// When the payment is canceled, this will be called
}

override fun onError(exception: BinancePayException) {
// When there is an error in the payment process,this will be called
}
}
val listener = PayListener()
2. To Pay

2.1 Crypto payments(C2B)

val param = BinancePayParam(merchantId, prepayId, timeStamp, nonceStr, certSn, sign)
val binancePay = BinancePayFactory.getBinancePay(context)
binancePay.pay(param, listener)

2.2 Transfer or send cryptos(C2C)

val binancePay = BinancePayFactory.getBinancePay(context)
binancePay.pay(orderId, type, listener)

Error Types:
Maybe you will encounter several situations:

  • UnInstall Error:This means that you have not installed the Binance app, and then a pop-up window will be displayed to guide you to download
  • UnSupported Error:This means that your Binance app version is too low, and then a pop-up window will be displayed to guide you to get the latest Binance app
  • Other Error:Will be called back to you via BinancePayListener

Integrate SDK for iOS

Requirements

  • iOS 10+
  • Swift 5.1+

Installation

Munual
  1. Download BinancePaySDK.xcframework
  2. Add BinancePaySDK.xcframework into Frameworks, Libraries and Embeded Content of your target
  3. Embed Type should be Embed & Sign

Usage

Pay
  1. Create Request Parameters:
// Crypto payments(C2B) parameters
public struct OrderInitParameters {
let merchantId: String
let prepayId: String
let timestamp: Int64
let noncestr: String
let certSn: String
let sign: String
let redirectScheme: String
}

// Transfer or send cryptos(C2C) parameters
public struct C2CInitParameters {
let id: String
let type: String
let redirectScheme: String
}
  1. Call api:
BinancePay.shared.pay(with: parameters, containerView: self.view) { (result) in
switch result {
case .success:
print("success")
case .failure(let error):
print("failure \(error)")
}
}

BinancePaySDK will show up an alert if user doesn't install Binance app on his/her device. The alert will show on the containerView.

  1. Error Types: Here are the errors you may get from BinancePaySDK:
public enum PayError: Error {
case invalidParameters(OrderInitParametersError)
case binanceAppNotInstalled
case binanceAppNotSupported
case openAppFailed
case fromBinanceApp(code: Int, message: String)
}

public enum OrderInitParametersError: Error {
case invalidMerchantId
case invalidPrepayId
case invalidTimestamp
case invalidNonceStr
case invalidCertSn
case invalidSign
case invalidRedirectScheme
}

Language

public enum languageMode {
case automatic // SDK automatically use the same language as iOS system
case manual(Language: Language) // You can specify the language
}

BinancePay.shared.languageMode = .automatic

FAQ

Unable to trigger the Binance App

Include Binance Pay in the plist file to trigger Binance app

<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.binance.app.binance</string>
<string>com.binance.pay.support</string>
</array>
Unable to redirect from Binance App back to your App
  1. Add your url scheme in Info Url Types
  2. Set this url-scheme as redirectScheme when using BinancePaySDK img
Did not receive callback

Under AppDelegate: include the BinancePay.shared.handle function to receive callback.

    func application(_ app: UIApplication, open url: URL, options:
[UIApplication.OpenURLOptionsKey : Any[ = [:]) -> Bool {
BinancePay.shared.handle(openURL: url)
}