Git Product home page Git Product logo

android-payment-sdk's Introduction

IPay88 Cambodia

We accept online payments from various methods, such as:

  • Credit or Debit cards (Visa, Mastercards, JCB, Diners Club & UnionPay, etc.)
  • e-Wallets (KHQR, Wing, PiPay, eMoney, Alipay, WeChat Pay, etc.)
  • Online Banking (ACLEDA XPay, CAMPU Direct Debit, Chip Mong Pay, AMK Online Card, Prince Bank QR, etc.)
  • Appendix I (1. PaymentId)
  • Demo App

Mobile Payment SDK - Android

1. SDK Payment Flow

  1. Your application initializes the library.
  2. After buyers complete their payments, the library returns a callback to your application with the status of the payment and the transaction id.
  3. After the library flow is complete, an activity result will be posted to be received by your application.

2. Version Supports

No Date By Version Supports Features
1 2022-Mar-06 kuntola 1.0.0 minSdk 21 --> targetSdk 31 - Redirect Payment
2 2022-May-09 kuntola 1.0.1 minSdk 21 --> targetSdk 31 - Open PlayStore if App's Deep-link not yet installed

Table of Contents

1. Requirements

  1. Please share your AppId inside module build.gradle to IPay88 team:
android {
    defaultConfig {
        applicationId "xxx.xxx.xxx"
    }
}
  1. Then IPay88 team will setup your AppId into IPay88 system to allow you to use IPay88 Mobile Payment channel.
  2. And then IPay88 team will share you these credentials:

2. Setup

2.1 Permissions inside AndroidManifest.xml

<manifest>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
</manifest>

2.2 ClientAppSecret inside AndroidManifest.xml

<manifest>
    <application>
        <meta-data
            android:name="kh.com.ipay88.sdk.ClientAppSecret"
            android:value="IPAY88-xxxxxxxxxxxxxxxxxxxxxxxxx" />
    </application>
</manifest>

2.3 Dependencies (To get a Git project into your build)

Step 1. Add the JitPack repository to your build file

  • Add it in your root build.gradle at the end of repositories:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  • If the above setting doesn't work, add it in your settings.gradle at the end of repositories:
dependencyResolutionManagement {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the IPay88 Payment SDK dependency

  • Add it in your module build.gradle inside dependencies:
dependencies {
    implementation 'com.github.ipay88-kh:android-payment-sdk:1.0.1'
}

3. Payment Request & Response

3.1 Payment Request

3.1.1 Payment Request Object

public class kh.com.ipay88.sdk.models.IPay88PayRequest

3.1.2 Payment Request Methods

Method Name Required Description
setEnvironment(Environment value) Swtich between SANDBOX (default) & PRODUCION environment. Please refer to 3.1.3 Environment
setMerchantCode(String value) Merchant Code that provided by IPay88, E.g. KH00001
setMerchantKey(String value) Merchant Key that provided by IPay88.
setPaymentID(int value) PaymentId is the value to request payment method to appear on IPay88 landing page. Please refer to Appendix I (1. PaymentId)
setRefNo(String value) Reference number for merchant reference purposes, should be unique for each transaction.
setAmount(String value) Final Amount to pay and in 2 decimal point, E.g. 10.90
setCurrency(Currency currency) Currency of transaction. Please refer to 3.1.4 Currency
setProdDesc(String value) Simple Product Description. Note: Special characters is not allowed.
setUserName(String value) Customer name in merchant's system. E.g. John Woo
setUserEmail(String value) Customer email address in merchant's system with valid email format, E.g. [email protected]
setUserContact(String value) Customer contact number in merchant's system, E.g. 60123436789
setRemark(String value) Remark for particular transaction. Note: Special characters is not allowed.
setBackendURL(String value) Specify a valid merchant callback URL when payment success. E.g. http://www.myshop.com/backend_page.php

3.1.3 Environment

public enum Environment {
    SANDBOX,
    PRODUCTION
}

3.1.4 Currency

public enum Currency {
    KHR,
    USD
}

3.2 Payment Response

3.2.1 Payment Response Object

public class kh.com.ipay88.sdk.models.IPay88PayResponse

3.2.2 Payment Response Methods

Method Name Required Description
String getMerchantCode() Merchant Code provided by iPay88 and use to uniquely identify the Merchant. E.g. KH00001
int getPaymentID() Please refer to Appendix I (1. PaymentId) for possible PaymentId value return to BackendPostURL.
String getRefNo() The request Reference number for merchant reference purposes, should be unique for each transaction.
String getAmount() Payment amount with two decimals
String getCurrency() Currency code that based on standard ISO (KHR or USD)
String getRemark() Remark for particular transaction.
String getTransID() iPay88 Transaction ID. E.g. T019988877700
String getAuthCode() Bank reference number. Note: Sometime bank may not return reference number to gateway.
String getStatus() Use to indicate payment status “1” – Success OR “0” – Fail
String getErrDesc() Payment status description. Please refer to Appendix I (3. Error Description)
String getSignature() SHA1 signature. Please refer to 5. Signature Response

4. How to Make Payment

4.1 Create Payment Request Object

// MARK: - Import SDK to your activity
import kh.com.ipay88.sdk.constants.IPay88Constants;
import kh.com.ipay88.sdk.models.IPay88PayRequest;
import kh.com.ipay88.sdk.models.IPay88PayResponse;
import kh.com.ipay88.sdk.utils.IPay88SDK;

// MARK: - Create 2 static variables to receive IPay88 payment response
static IPay88PayResponse payResponse;
static String errorMsg;

TextView tvStatus;

// MARK: - IPay88 Checkout
IPay88PayRequest payRequest = new IPay88PayRequest();
payRequest.setEnvironment(IPay88PayRequest.Environment.SANDBOX);
payRequest.setMerchantCode("KH00001");
payRequest.setMerchantKey("Apple88KEY");
payRequest.setPaymentID(1);
payRequest.setRefNo("ORD1188");
payRequest.setAmount("1.00");
payRequest.setCurrency(IPay88PayRequest.Currency.USD);
payRequest.setProdDesc("Top Up (SDK)");
payRequest.setUserName("Tola KUN");
payRequest.setUserEmail("[email protected]");
payRequest.setUserContact("017847800");
payRequest.setRemark("aOS");
payRequest.setBackendURL("http://www.myshop.com/backend_page.php");

4.2 Create Payment Callback

  • Create a Java class and implement these 2 interfaces:
public interface kh.com.ipay88.sdk.utils.IPay88Callback
public interface java.io.Serializable
  • For Example:
public class MainActivityCallback implements IPay88Callback, Serializable {
    @Override
    public void onResponse(IPay88PayResponse payResponse) {
        MainActivity.payResponse = payResponse;
    }

    @Override
    public void onFailure(String message) {
        MainActivity.errorMsg = message;
    }
}

4.3 Invoke Checkout Function

IPay88SDK.checkout(MainActivity.this, payRequest, new MainActivityCallback());

4.4 Handle Payment Response Object

  • Need to override
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
}
  • For Example:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // MARK: - IPay88 Payment Response
    if (requestCode == IPay88Constants.PAY_REQUEST_CODE
            && resultCode == Activity.RESULT_OK
            && data != null
            && MainActivity.payResponse != null) {
        
        String status = MainActivity.payResponse.getStatus().equals("1") ? "SUCCESS" : "FAILED";
        String json = IPay88PayResponse.GenerateJSONData(MainActivity.payResponse, true);
        tvStatus.setText(status + "\n" + json);

    } else if (requestCode == IPay88Constants.PAY_REQUEST_CODE
            && resultCode == Activity.RESULT_CANCELED
            && data != null
            && MainActivity.errorMsg != null) {
        
        tvStatus.setText(MainActivity.errorMsg);

    }
}

5. Signature Response

  • If the Merchant request is successful the response message will contain as SHA1 hashed signature.

  • The hash signature for the response is a hash of the following fields:

    1. MerchantKey (Provided by iPay88 and share between iPay88 and merchant only)
    2. MerchantCode
    3. PaymentId
    4. RefNo
    5. Amount
    6. Currency
    7. Status
    
  • The fields must be set in the following order, (MerchantKey & MerchantCode & PaymentId & RefNo & Amount & Currency & Status)

  • For Example:

    MerchantKey = "Apple88KEY"
    MerchantCode = "KH00001"
    PaymentId = "1"
    RefNo = "ORD1188"
    Amount = "1.00" (Note: Remove the “.” and “,” in the string before hash)
    Currency = "KHR"
    Status = "1"
    
    • The hash would be calculated on the following string:
    Apple88KEYKH00001ORD1188100KHR1
    
    • The resulting has signature value equals to (using SHA1 algorithm)
    KiCecyU86ZOFk15jXwOAvHdw/1M=
    
  • Test URL: https://payment.ipay88.com.kh/epayment/testing/TestSignature_response.asp

Appendix I

1. PaymentId

  • Set PaymentId = 0, it will show all registered payment methods to the customer.

1.1 Credit & Debit Card

Payment Method Name PaymentId (USD) Logo
Credit Card 1
UnionPay 15

1.2 eWallet

Payment Method Name PaymentId (USD) PaymentId (KHR) Logo
eMoney 9 10
Pi Pay 11
Alipay 233
Wing 235 236
WeChat Pay 240
KHQR 248 249

1.3 Online Banking

Payment Method Name PaymentId (USD) PaymentId (KHR) Logo
Acleda XPAY 3 4
Chip Mong Pay 238 239
Campu Direct Debit 242 243
AMK Online Card 246 247
Prince Bank QR 251 252

2. Currency

Currency Code Description
KHR Cambodia Riel
USD US Dollar

3. Error Description

Message Description
Duplicate reference number Reference number must be unique for each transaction.
Invalid merchant The merchant code does not exist.
Invalid parameters Some parameter posted to iPay88 is invalid or empty.
Overlimit per transaction You exceed the amount value per transaction.
Payment not allowed The Payment method you requested is not allowed for this merchant code, please contact iPay88 Support to verify what payment method available for the merchant account.
Permission not allow Your AppId or the shared credentials is not match with the information registered in iPay88 merchant account. Please contact IPay88 team.

4. Demo

IPAY88SDK-Demo.apk

android-payment-sdk's People

Contributors

ipay88-kh avatar bardiaalavi-2020 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.