ClickPay SDK makes the integration with ClickPay payment gateway very easy, by providing a ready-made payment screen that handles the card entry and billing & shipping info and completes the missing details.
In this article, you will be going to know about
Requirements
Library requires at minimum Java 7 or Android 5.1. Then, you will have to include the following dependencies:
implementation 'sa.com.clickpay:payment-sdk:6.1.9' |
Known Coroutine issue
In case you faced a "Duplicated class" dependency conflict with the coroutine API, add the following in your app Gradle file to avoid this issue.
configurations.all { resolutionStrategy { exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-debug" } } |
Proguard
If you are using ProGuard you might need to exclude the library classes.
-keep public class com.payment.paymentsdk.**{*} |
Usage
Pay now (in Kotlin)
val profileId = "PROFILE_ID" val serverKey = "SERVER_KEY" val clientLey = "CLIENT_KEY" val locale = PaymentSdkLanguageCode.EN or PaymentSdkLanguageCode.AR val screenTitle = "Test SDK" val cartId = "123456" val cartDesc = "cart description" val currency = "SAR" val amount = 20.0 val tokeniseType = PaymentSdkTokenise.NONE // tokenise is off or PaymentSdkTokenise.USER_OPTIONAL // tokenise if optional as per user approval or PaymentSdkTokenise.USER_MANDATORY // tokenise is forced as per user approval or PaymentSdkTokenise.MERCHANT_MANDATORY // tokenise is forced without user approval val transType = PaymentSdkTransactionType.SALE; or PaymentSdkTransactionType.AUTH val tokenFormat = PaymentSdkTokenFormat.Hex32Format() or PaymentSdkTokenFormat.NoneFormat() or PaymentSdkTokenFormat.AlphaNum20Format() or PaymentSdkTokenFormat.Digit22Format() or PaymentSdkTokenFormat.Digit16Format() or PaymentSdkTokenFormat.AlphaNum32Format() val billingData = PaymentSdkBillingDetails( "City", "2 digit iso Country code", "email1@domain.com", "name ", "phone", "state", "address street", "zip") val shippingData = PaymentSdkShippingDetails( "City", "2 digit iso Country code", "email1@domain.com", "name ", "phone", "state", "address street", "zip") val configData = PaymentSdkConfigBuilder(profileId, serverKey, clientKey, amount ?: 0.0, currency) .setCartDescription(cartDesc) .setLanguageCode(locale) .setMerchantIcon(resources.getDrawable(R.drawable.bt_ic_amex)) .setBillingData(billingData) .setMerchantCountryCode("AE") // ISO alpha 2 .setShippingData(shippingData) .setCartId(orderId) .setTransactionType(transType) .showBillingInfo(false) .showShippingInfo(true) .forceShippingInfo(true) .setScreenTitle(screenTitle) .build() startCardPayment(this, configData, callback=this)orstartSamsungPayment(this, configData, "samsungpay token",callback=this) override fun onError(error: PaymentSdkError) { Log.d(TAG_PAYTABS, "onError: $error") Toast.makeText(this, "${error.msg}", Toast.LENGTH_SHORT).show() } override fun onPaymentFinish(PaymentSdkTransactionDetails: PaymentSdkTransactionDetails) { Toast.makeText(this, "${paymentSdkTransactionDetails.paymentResult?.responseMessage}", Toast.LENGTH_SHORT).show() Log.d(TAG_PAYTABS, "onPaymentFinish: $paymentSdkTransactionDetails") } override fun onPaymentCancel() { Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show() Log.d(TAG_PAYTABS, "onPaymentCancel:") } |
Pay now (in Java)
String profileId = "PROFILE_ID"; String serverKey = "SERVER_KEY"; String clientKey = "CLIENT_KEY"; PaymentSdkLanguageCode locale = PaymentSdkLanguageCode.EN; String screenTitle = "Test SDK";String cartId = "123456"; String cartDesc = "cart description";String currency = "AED"; double amount = 20.0; PaymentSdkTokenise tokeniseType = PaymentSdkTokenise.NONE; // tokenise is off or PaymentSdkTokenise.USER_OPTIONAL // tokenise if optional as per user approval or PaymentSdkTokenise.USER_MANDATORY // tokenise is forced as per user approval or PaymentSdkTokenise.MERCHANT_MANDATORY // tokenise is forced without user approval PaymentSdkTransactionType transType = PaymentSdkTransactionType.SALE; or PaymentSdkTransactionType.AUTH PaymentSdkTokenFormat tokenFormat = new PaymentSdkTokenFormat.Hex32Format(); or new PaymentSdkTokenFormat.NoneFormat() or new PaymentSdkTokenFormat.AlphaNum20Format() or new PaymentSdkTokenFormat.Digit22Format() or new PaymentSdkTokenFormat.Digit16Format() or new PaymentSdkTokenFormat.AlphaNum32Format() PaymentSdkBillingDetails billingData = new PaymentSdkBillingDetails( "City", "2 digit iso Country code", "email1@domain.com", "name ", "phone", "state", "address street", "zip" ); PaymentSdkShippingDetails shippingData = new PaymentSdkShippingDetails( "City", "2 digit iso Country code", "email1@domain.com", "name ", "phone", "state", "address street", "zip" ); PaymentSdkConfigurationDetails configData = new PaymentSdkConfigBuilder(profileId, serverKey, clientKey, amount, currency) .setCartDescription(cartDesc) .setLanguageCode(locale) .setBillingData(billingData) .setMerchantCountryCode("AE") // ISO alpha 2 .setShippingData(shippingData) .setCartId(cartId) .setTransactionType(transType) .showBillingInfo(false) .showShippingInfo(true) .forceShippingInfo(true) .setScreenTitle(screenTitle) .build();PaymentSdkActivity.startCardPayment(this, configData, this); @Override public void onError(@NotNull PaymentSdkError paymentSdkError) { } @Override public void onPaymentCancel() { } @Override public void onPaymentFinish(@NotNull PaymentSdkTransactionDetails paymentSdkTransactionDetails) { }
|
Tokenization
To enable tokenization (for recurring or any other services that depend on auto-detection from the customers instead of saving credit cards details), please follow the below instructions.
1- Request token and transaction reference by passing tokeniseType and Format
.setTokenise(PaymentSdkTokenise.MERCHANT_MANDATORY,PaymentSdkTokenFormat.Hex32Format()) |
After passing those parameters, you will receive token and transaction references in the delegate, save them for future usage.
.setTokenisationData(token = "", transactionReference = "") |
Overriding Resources
In case you need to Override Fonts, you will have to add your custom fonts files with these names:
payment_sdk_primary_font.tff && payment_sdk_secondary_font.tff.
In case you need to Override Strings, Colors or Dimens add the resource you need to override from the below resources with the value you want.
You can find the keys with the default values here:
- English
- Arabic
<resourse> // to override colors <color name="payment_sdk_primary_color">#5C13DF</color> <color name="payment_sdk_secondary_color">#FFC107</color> <color name="payment_sdk_primary_font_color">#111112</color> <color name="payment_sdk_secondary_font_color">#6D6C70</color> <color name="payment_sdk_separators_color">#FFC107</color> <color name="payment_sdk_stroke_color">#673AB7</color> <color name="payment_sdk_button_text_color">#FFF</color> <color name="payment_sdk_title_text_color">#FFF</color> <color name="payment_sdk_button_background_color">#3F51B5</color> <color name="payment_sdk_background_color">#F9FAFD</color> <color name="payment_sdk_card_background_color">#F9FAFD</color> <color name="payment_sdk_status_bar_color">#FFC107</color> // to override dimens <dimen name="payment_sdk_primary_font_size">17sp</dimen> <dimen name="payment_sdk_secondary_font_size">15sp</dimen> <dimen name="payment_sdk_separator_thickness">1dp</dimen> <dimen name="payment_sdk_stroke_thickness">.5dp</dimen> <dimen name="payment_sdk_input_corner_radius">8dp</dimen> <dimen name="payment_sdk_button_corner_radius">8dp</dimen> </resourse> |
Theme
Use the following guide to customize the colors, font, and logo by configuring the theme and passing it to the payment configuration.