Skip to content
Android SDK for NewPay Integration
Java
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
NewPaySDK
app Update MainActivity.java Aug 15, 2019
gradle/wrapper
.gitignore update readme Jun 22, 2019
LICENSE Create LICENSE Jul 22, 2019
README.md
README1.md update readme Jun 22, 2019
build.gradle add NewPaySdk Feb 15, 2019
gradle.properties add NewPaySdk Feb 15, 2019
gradlew add NewPaySdk Feb 15, 2019
gradlew.bat add NewPaySdk Feb 15, 2019
settings.gradle add NewPaySdk Feb 15, 2019

README.md

NewPaySDK Android Documentation

1.Dependencies

Add the dependencies to your app-level build.gradle file.

implementation 'org.newtonproject.newpay.sdk:newpay:2.0.4'

//The signature tools in Demo. On production environment, the signature information must be from server.

implementation files('libs/crypto-3.3.1-android.jar')
implementation files('libs/utils-3.3.1-android.jar')
implementation 'com.madgag.spongycastle:core:1.58.0.0'
implementation "com.madgag.spongycastle:prov:1.58.0.0"

2. Init NewPaySDK

// in release environment
NewPaySDK.init(getApplication());

// in testnet, beta, dev, etc. environment
NewPaySDK.init(getApplication(), Environment.DEVNET);

3. Get Profile and SigMessage

To get the profile information, call the requestProfile function and catch the result in onActivityResult. In any case the SDK returns the requestCode NewPaySDK.REQUEST_CODE_NEWPAY.

get the login parameters

Observable<BaseResponse<NewAuthLogin>> getAuthLogin(@Field("os") String os);

{
    "uuid": "session_id,random string",
    "dapp_id": "your dapp id",
    "protocol": "HEP",
    "version": "1.0",
    "ts": "timestamp",
    "nonce": "random string",
    "action": "hep.auth.login",
    "scope": "1", // 1 is summary, 2 is detail for profile.
    "memo": "request memo",
    "sign_type": "secp256r1",
    "signature": "0x......."
}

send the login parameter to Newpay

NewPaySDK.requestProfile(Context context, NewAuthLogin authLogin);

receive the user profile from newpay

if(requestCode == NewPaySDK.REQUEST_CODE_NEWPAY) {
    String profile = data.getStringExtra(SIGNED_PROFILE);
    if(!TextUtils.isEmpty(profile)){
        profileInfo = gson.fromJson(profile, HepProfile.class);
        cellphoneTextView.setText(profileInfo.cellphone);
        nameTextView.setText(profileInfo.name);
        newidTextView.setText(profileInfo.newid);
        Log.e(TAG, "Profile:" + profileInfo);
        if(!TextUtils.isEmpty(profileInfo.avatarPath)) {
            Picasso.get().load(profileInfo.avatarPath).into(imageView);
        }
    }
}

Verify the profile information on server

{
    "signature": "0x...",
    "sign_type": "secp256r1",
    "uuid": "uuid random string",
    "name": "profile name",
    "country_code": "user's country code",
    "cellphone": "user's cellphone",
    "avatar": "avatar path",
    "address": "user's address",
    "newid": "user's newid ",
    "invite_code": "user's invite code"
}

4. Request Pay

get the pay parameters

Observable<BaseResponse<NewAuthPay>> getAuthPay(@Field("newid") String newid, @Field("os") String os);

{
    "uuid": "session_id,random string",
    "dapp_id": "your dapp id",
    "protocol": "HEP",
    "version": "1.0",
    "ts": "timestamp",
    "nonce": "random string",
    "action": "hep.pay.order",
    "description": "order description",
    "price_currency": "CNY", //NEW...
    "total_price": "100",
    "order_number": "order number",
    "seller": "sellerNewid",
    "customer": "customer Newid",
    "broker": "broker Newid",
    "sign_type": "secp256r1",
    "signature": "0x......."
}

send the pay parameter to newpay

  NewPaySDK.pay(Activity activity, NewAuthPay pay);

receive the pay information from newpay

if(requestCode == NewPaySDK.REQUEST_CODE_NEWPAY_PAY){
    String res = data.getStringExtra(SIGNED_PAY);
    ConfirmedPayment payment = gson.fromJson(res, ConfirmedPayment.class);
    Toast.makeText(this, "txid is:" + payment.txid, Toast.LENGTH_SHORT).show();
}

Verify the pay information on server

{
    "signature": "0x...",
    "sign_type": "secp256r1",
    "txid": "transaction id",
    "ts": "timestamp",
    "nonce": "random string",
    "order_number": "order number",
    "dapp_id": "dapp id",
    "uuid": "session id, random string"
}

5. Request submit place order

get the proof parameters

Observable<BaseResponse<NewAuthProof>> getAuthProof(@Field("newid") String newid, @Field("os") String os);

{
    "uuid": "session_id,random string",
    "dapp_id": "your dapp id",
    "protocol": "HEP",
    "version": "1.0",
    "ts": "timestamp",
    "nonce": "random string",
    "action": "hep.proof.submit",
    "proof_hash": "proof hash"
    "sign_type": "secp256r1",
    "signature": "0x......."
}

send the proof parameter to newpay

NewPaySDK.placeOrder(Activity activity, NewAuthProof authProof);

#### receive the proof information from newpay
```java
if(requestCode == NewPaySDK.REQUEST_CODE_PUSH_ORDER) {
    String res = data.getStringExtra(SIGNED_PROOF);
    ConfirmedProof proof = gson.fromJson(res, ConfirmedProof.class);
    Toast.makeText(this, proof.proofHash, Toast.LENGTH_SHORT).show();
}

Verify the proof information on server

{
    "signature": "0x...",
    "sign_type": "secp256r1",
    "proof_hash": "proof hash",
    "ts": "timestamp",
    "nonce": "random string",
    "dapp_id": "dapp id",
    "uuid": "session id, random string"
}
You can’t perform that action at this time.