Documentation - Android webteh modul

Versions

  • Version 1.8.2

    • Added charge functionality, now it's possible to pay with payment method without requiring user interaction
    • Updated application example
  • Version 1.8.1
    • Added add payment method with cancel transaction functionality (void after authorization)
    • Refactored existing code
    • Added add payment method example

Description

Module encapsulates basic functionality for payment system.

Installation


Add following in your application

  • settings.gradle add include ':app', ':pay'
  • build.gradle add compile project(':pay')

Usage & requirements


Overall functionality is shown in flow charts:

Pay module functionality is provided in two classes:

  • WebtehWebView class
  • PgwModule & PgwApi class

To use WebtehWebView add-card and pay-cvv developer must provide auth_token issued to merchant. Same case is for PgwModule.

Auth token is used to authenticate merchant and to decide which payment gateway endpoint will be used (test or production).

Note: if you do not have auth token please contact [email protected] to receive one.

WebtehWebView


Functionality

Include WebtehWebView in your layout or create dynamically in java code.

Usage example: code

  • Find in layour or create new instance in java code
    WebtehWebView webtehWebView = (WebtehWebView) findViewById(R.id.webView);
  • Instantiate PgwModule - PgwModule pgwModule = new PgwModule("auth_token", BuildConfig.DEBUG)
  • Create new order number - final String orderNumber = String.valueOf(System.currentTimeMillis()); or use your own business logic
  • Implement and instantiate TransactionLifecycleDelegate - final TransactionLifecycleDelegate transactionLifecycleDelegate = new TransactionLifecycleDelegateImpl();
  • Pick ResponseType - final TransactionLifecycleAdapter.ResponseType responseType = TransactionLifecycleAdapter.ResponseType.TransactionSuccess;
  • Instantiate TransactionLifecycleAdapter - final TransactionLifecycleAdapter transactionLifecycleAdapter = new TransactionLifecycleAdapter(orderNumber, pgwModule.getApi(), "client_secret", responseType, transactionLifecycleDelegate);
  • Initialize WebtehWebView - webtehWebView.initialize(transactionLifecycleAdapter, BuildConfig.DEBUG, 10000);

  • Invoke addCard or
    AddCardModel cardModel = new AddCardModelBuilder()
      .setAmount("1250")
      .setMerchantId("007007007007")
      .setAuthToken("00001111222233330000111122223333")
      .setCurrency(AddCardModel.Currency.EUR.toString())
      .setOrderInfo("order ifno")
      .setOrderNumber(String.valueOf(System.currentTimeMillis()))
      .setSign("signature")
      .setClientSecret("MegaSecretKey")
      .setClient("android")
      .createAddCardModel();
    //invoke addCard
    webtehWebView.addCard(cardModel);
  • invoke payCvv
    
    PayCvvModel payCvvModel = new PayCvvModelBuilder()
      .setAmount("1250")
      .setMerchantId("007007007007")
      .setAuthToken("00001111222233330000111122223333")
      .setCurrency(AddCardModel.Currency.EUR.toString())
      .setOrderInfo("order ifno")
      .setOrderNumber(String.valueOf(System.currentTimeMillis()))
      .setSign("signature")
      .setClientSecret("MegaSecretKey")
      .setPmAlias("xeNZhOQfRjtwOxLvRJK0EhJ4UogzSBR9kWMnep8c")
      .setClient("cvv_android")
      .createPayCvvModel();
    //invoke payCvv
    webtehWebView.payCvv(payCvvModel);
    
    

Models

-AddCard jsonschema
Proxy uses json schemas to validate input received on endpoints. For example this schema is used to validate on /add-card endpoint.
-PayCvv json schema
Proxy uses json schemas to validate input received on endpoints. For example this schema is used to validate on /pay-cvv endpoint.
-TransactionError
Model sent to TransactionLifecycle#transactionFailure(TransactionError error)
-TransactionSuccess
-TransactionErrorDetailed

PgwModule & PgwApi


Usage example - checkOrderId use checkOrder

    
PgwModule pgwModule = new PgwModule(BuildConfig.PGW_AUTH_KEY, BuildConfig.DEBUG);
final PgwApi api = pgwModule.getApi();
String orderNumber = "1482240015006";
String digest = "16ef726f3111de11ee8e4e47431bebad58e0ce14"; // sha1(merchant_key + orderNumber)
//Merchant key is provided on ipg merchant dashboard

api.checkOrderId(orderNumber, digest)
    .subscribeOn(Schedulers.io())
    .observeOn(AndroidSchedulers.mainThread())
    .subscribe(new Action1<ShowOrderResponse>() {
            @Override
            public void call(ShowOrderResponse showOrderResponse) {
                Log.d(TAG + "checkOrderId", "call: " + showOrderResponse);
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                Log.d(TAG + "checkOrderId", "call: " + throwable.getMessage(), throwable);
            }
    });
    

Usage example - checkOrder

NOTE - checkOrder will only work with new transactions (transactions after api update)

    
PgwModule pgwModule = new PgwModule(BuildConfig.PGW_AUTH_KEY, BuildConfig.DEBUG);
final PgwApi api = pgwModule.getApi();
String orderNumber = "1484635152";
String digest = "a67249a8f0de783a06c76c83bdb5e9fec7f20f9a"; // sha1(merchant_key + orderNumber)
//Merchant key is provided on ipg merchant dashboard

api.checkOrder(orderNumber, digest)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<TransactionSuccess>() {
                    @Override
                    public void call(TransactionSuccess transactionSuccess) {
                        Log.d(TAG + "checkOrder", "call: " + transactionSuccess);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.d(TAG + "checkOrderError", "call: " + throwable.getMessage(), throwable);
                    }
                });
    

Usage example - checkTransaction

    
PgwModule pgwModule = new PgwModule(BuildConfig.PGW_AUTH_KEY, BuildConfig.DEBUG);
final PgwApi api = pgwModule.getApi();
int transactionId = 80547;

api.checkTransaction(transactionId)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Action1<Transaction>() {
            @Override
            public void call(Transaction transaction) {
                Log.d(TAG + "checkTransaction", "call: " + transaction);
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                Log.d(TAG + "checkTransactionError", "call: " + throwable.getMessage(), throwable);
            }
        });
    

Usage example - getError

    
PgwModule pgwModule = new PgwModule(BuildConfig.PGW_AUTH_KEY, BuildConfig.DEBUG);
final PgwApi api = pgwModule.getApi();
int errorId = 19;

api.getError(errorId)
        .subscribeOn(Schedulers.io())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new Action1<TransactionErrorDetailed>() {
            @Override
            public void call(TransactionErrorDetailed transactionErrorDetailed) {
                Log.d(TAG + "getError", "call: " + transactionErrorDetailed);
            }
        }, new Action1<Throwable>() {
            @Override
            public void call(Throwable throwable) {
                Log.e(TAG + "getError", "call: " + throwable.getMessage(), throwable);
            }
                });