Android

Over The Ottu Checkout which is Android SDK, helps you to make your payment process easy and quick within your Android app, in addition it provides UI screen and elements customizable empowering you to collect payment details of your user.

For optimal security, call REST APIs from server-side implementations, not client-side applications such as mobile apps or web browsers.

Simplified security: Sensitive data will be collected easily according to PCI-compliant, by sending it directly to Ottu instead of sending it to your server.

Native UI: Ottu offers native screens and elements for collecting payment details.

Localized: Both English, Arabic localizations are supported.

The Ottu Checkout SDK collects data to help in improving the products and services and prevent fraud. This data is never used for advertising and is not rented, sold, or given to advertisers.

IDE is required to develop an android app. SDK is compatible with minimum SDK 22 and above.

Firstly, a session token should be created by Ottu public API, then SDK could be initialized. See Rest API.

For "Api_Key" API Public key sohuld be used.

Put below dependency into your Gradle.

allprojects {
    repositories {
        ...
        maven {
            url 'https://jitpack.io'
        }
    }
}

dependencies {
    implementation 'com.github.ottuco:ottu-android-private-sdk:1.0.18'
}

Below is the sample code of how you can use Ottu Payment SDK.

Ottu ottuPaymentSdk = new Ottu(MainActivity.this);
ottuPaymentSdk.setApiId("apiKey"); // set Api Key which is get from Ottu merchant account
ottuPaymentSdk.setMerchantId("merchant_id");
ottuPaymentSdk.setSessionId("session_id"); // Retrive from public API
ottuPaymentSdk.setAmount("100.00"); // String Value
ottuPaymentSdk.setLocal("lang"); // en or ar
ottuPaymentSdk.build();

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == OttuPaymentResult) {
            SocketRespo paymentResult = (SocketRespo) data.getSerializableExtra("paymentResult");
            textView.setText(paymentResult.status); // success || failed || cancel
            textView.setText(paymentResult.message);
            textView.setText(paymentResult.order_no);
            textView.setText(paymentResult.operation);
        }

    }
}

If you are using fragments, you will need to add BroadcastReseiver in onActivityResult to add your success-failure logic in your fragment.

PAYMENT_SUCCESS = "paymentSuccess" // add in your constant accordingly
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == OttuPaymentResult) {
            SocketRespo paymentResult = (SocketRespo) data.getSerializableExtra("paymentResult");
            textView.setText(paymentResult.status); // success || failed || cancel
            if (paymentResult.status.equals("success")) {
                Intent intent = Intent(PAYMENT_SUCCESS)
                sendBroadcast(intent)
            }
        }
    }
}

// register your broadcast
activity.registerReceiver(
    paymentReceiver,
    IntentFilter(PAYMENT_SUCCESS)
)

// then you will receive it in your fragment with your action PAYMENT_SUCCESS
BroadcastReceiver paymentReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(PAYMENT_SUCCESS)) {
            // add your code 
        }
    }
};

You may need to include the following lines in your progard-rules.pro file if enable progard or minifyEnble.

-keep class Ottu** { *; }

Set STC Pay button in XML.

<
Ottu.util.StcPayButton
android: id = "@+id/stcBtn"
android: layout_gravity = "right"
android: layout_width = "100dp"
android: layout_height = "40dp" / >

Set credential and transaction detail to make payment before user click on STC Pay button.

stcPayButton.setApiId("API_key");
stcPayButton.setMerchantId("Mercent_id");
stcPayButton.setLocal("en"); // Language
stcPayButton.setCreateTransaction("e_commerce", String.valueOf(amount) // Amount
    , "KWD" // Currency code
    , "https://postapp.knpay.net/disclose_ok/" //  Discloser url
    , "https://postapp.knpay.net/redirected/" //  Redirect url
    , "customer_id", "1234567890" // Mobile number
    , "2:00"); // Transaction Time Limite

//   Get payment result in onActivityResult menthod in Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == OttuPaymentResult) {
            SocketRespo paymentResult = (SocketRespo) data.getSerializableExtra("paymentResult");
            textView.setText(paymentResult.status); // success || failed || cancel
            textView.setText(paymentResult.message);
            textView.setText(paymentResult.order_no);
            textView.setText(paymentResult.operation);
        }

    }
}

Avoid to set click listener for STC Pay button because it's managed by StcPayButton class.

Last updated