Skip to content
Payment SDK
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.
pt/paypay/paymentsdk/paymentsdk repositories added, readme.md added Mar 21, 2019
readme.md readme.md changed. Error response info added Mar 21, 2019

readme.md

Android - Card Payment SDK

ACIN

Build Status

CardPaymentSDK is a library to make payments through several payment methods painless. It uses PayPay as an endpoint to establish a payment security channel.

Android Version and Dependecy specification

The Android API minimum requirements:

  • Target Device version: 17 (v4.2)
  • SDK compile version: 28 (v9.0)

Inside build.gradle in (Module: App)

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.yourapplication"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
    }
}

Repositories must be added in build.gradle (Project: YourProjectName) :

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url  "https://dl.bintray.com/terl/lazysodium-maven"
        }
        maven {
            url  "https://paypay.pt/repositories/android/paymentsdk"
        }
    }
}

Dependencies must be added inside build.gradle (Module: app):

dependencies {
    releaseImplementation 'pt.paypay.paymentsdk:paymentsdk:1.0.1-Debug'
    debugImplementation 'pt.paypay.paymentsdk:paymentsdk:1.0.1-Staging'
    stagingImplementation 'pt.paypay.paymentsdk:paymentsdk:1.0.1-Release'
    implementation "net.java.dev.jna:jna:4.5.0@aar"
}

Usage

Creating basic credentials:

PaymentTokenBuilder tokenBuilder = PaymentFactory.createTokenBuilder()
                                                 .createEntityConfig("abc", "123", "503098000")
                                                 .createCustomer("123", "962295141", "José", "Silva", "js@acin.pt")
                                                 .createDescription(100, "123", "PaymentAPI parquimetro")
                                                 .addAdditionalData("keyXPTO", "valueXPTO") // Optional Additional data
                                                 .addAdditionalData("keyPTO", "valuePTO"); // Optional Additional data

Creating credentials for customers outside Portugal:

PaymentTokenBuilder tokenBuilder = PaymentFactory.createTokenBuilder()
                                                 .createEntityConfig("abc", "123", "503098000")
                                                 .createCustomer("123", "962295141", "José", "Silva", "js@acin.pt", "44") // England phone code
                                                 .createDescription(100, "123", "PaymentAPI parquimetro")
                                                 .addAdditionalData("keyXPTO", "valueXPTO") // Optional Additional data
                                                 .addAdditionalData("keyPTO", "valuePTO"); // Optional Additional data

Creating MBWay payment with allowRegistration and registration id:

tokenBuilder.addMBWAYPayment("962295141" true, "id123");

Creating an MBWay payment only with the number:

tokenBuilder.addMBWAYPayment("962295141");

Creating a Card payment:

List<String> cards = new Arraylist<String>;
cards.add("123456");
tokenBuilder.addCardPayment(true, cards);

In the .xml layout file:

<pt.paypay.cardpaymentsdk.services.WebViewService
    android:id="@+id/cardWebView"
    android:clickable="true"
    android:visibility="gone"
    ...
/>

Initializing a payment. This operation is mandatory:

public class MainActivity extends PaymentActivityManager {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final WebViewService myWebView =  findViewById(R.id.cardWebView);
        PaymentTokenBuilder tokenBuilder = PaymentFactory.createTokenBuilder()
                                                         .createEntityConfig("abc", "123", "503098000")
                                                         .createCustomer("1", "962295141", "José", "Silva", "js@acin.pt")
                                                         .createDescription(100, "123", "PaymentAPI parquimetro")
                                                         .addAdditionalData("keyXPTO", "valueXPTO") // Optional Additional data
                                                         .addAdditionalData("keyPTO", "valuePTO") // Optional Additional data
                                                         .addMBWAYPayment("962295141");
        initializeManager(serviceWebView, tokenBuilder);
    }
}

Initializing payment. Pass the PaymentEventListener instance. All declared methods will be called if the event happens, as it shows:

public class MainActivity extends PaymentActivityManager {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final WebViewService myWebView =  findViewById(R.id.cardWebView);
        PaymentTokenBuilder tokenBuilder = PaymentFactory.createTokenBuilder()
                                                         .createEntityConfig("abc", "123", "503098000")
                                                         .createCustomer("1", "962295141", "José", "Silva", "js@acin.pt")
                                                         .createDescription(100, "123", "PaymentAPI parquimetro")
                                                         .addAdditionalData("keyXPTO", "valueXPTO") // Optional Additional data
                                                         .addAdditionalData("keyPTO", "valuePTO") // Optional Additional data
                                                         .addMBWAYPayment("962295141");
        initializeManager(serviceWebView, tokenBuilder);
        initializePayment(new CustomPaymentEventListener() {
            @Override
            public void onPaymentReady(PaymentReady event) { }

            @Override
            public void onPaymentPending(PaymentPending event) { }

            @Override
            public void onPaymentSuccess(PaymentSuccess event) { }

            //More events...
        });
    }
}

Or a alternatively you can just override PaymentActivityManager listener:

public class MainActivity extends PaymentActivityManager {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        final WebViewService myWebView =  findViewById(R.id.cardWebView);
        PaymentTokenBuilder tokenBuilder = PaymentFactory.createTokenBuilder()
                                                         .createEntityConfig("abc", "123", "503098000")
                                                         .createCustomer("1", "962295141", "José", "Silva", "js@acin.pt")
                                                         .createDescription(100, "123", "PaymentAPI parquimetro")
                                                         .addAdditionalData("keyXPTO", "valueXPTO") // Optional Additional data
                                                         .addAdditionalData("keyPTO", "valuePTO") // Optional Additional data
                                                         .addMBWAYPayment("962295141");
        initializeManager(serviceWebView, tokenBuilder);
        initializePayment();
    }

    @Override
    public void onPaymentReady(PaymentReady event) {
            // Your code goes here.
    }

    @Override
    public void onPaymentPending(PaymentPending event) {
            // Your code goes here.
    }

    @Override
    public void onPaymentSuccess(PaymentSuccess event) {
            // Your code goes here.
    }
}

All available methods:

  • onPaymentCancelled(PaymentCancel event) { }
  • onPageReady(PageReady event) { }
  • onPageLoading(PageLoading event) { }
  • onPageError(WebView view, WebResourceRequest request, WebResourceError error) { }
  • onPaymentError(PaymentError event) { }
  • onTokenReceive(PaymentToken response) { }
  • onTokenReceiveError(Throwable e) { }
  • onEvent(PaymentToken event) { }
  • public void onPaymentSuccess(PaymentSuccess event)
  • onActionRequest(ActionRequest actionRequest) { }
  • onActionsAvailable(List<String> actions) { }
  • shouldOverrideUrlLoading(String url) { return url;}
  • onError(Throwable e) { }
  • onCardTokenReceive(PaymentToken token) { }
  • onTokenStateResponse(CheckoutStateToken stateDetails) { }
  • onPaymentLoading(PaymentLoading paymentLoading) { }
  • makeActionRequest(String action) { }

All available Error Response Codes:

* e0001 - Checkout token expired
* e0002 - Could not connect to push service
* e0003 - Could not subscribe to push service
* e0004 - User cancelled during checkout
* e4000 - Operation completed successfully
* e4007 - Financial operation canceled by the merchant
* e4010 - User rejected alias association
* e4020 - Financial transaction declined in the application
* e4100 - Internal service error
* e4101 - Execution timeout
* e4102 - Message content validation error
* e4103 - Invalid POS
* e4104 - Operation declined due to problem with user service.
* e4110 - Unauthorized Alias Type for the merchant
* e4111 - Invalid alias format
* e4112 - Duplicate alias
* e4113 - Uknown alias
* e4120 - Duplicate financial operation
* e4121 - Invalid financial operation type
* e4122 - Operation declined
* e4123 - Financial operation not found
* e4124 - Alias association not possible
* e4125 - Financial operation declined
* e4201 - Financial operation expired
* e4202 - Invalid phone number
* e4999 - Unknown  error

Validating SDK customized Internal Errors (Enum):

@Override
public void onPaymentError(PaymentError event) {
    if (PaymentError.Error.CANCELED_BY_USER == event.getError()) {
        // Show cancelled by user layout
    }
}

All available actions:

  • ACTION_PAY - PaymentAction.ACTION_PAY
  • ACTION_CANCEL - PaymentAction.ACTION_CANCEL
  • ACTION_UPDATE - PaymentAction.ACTION_UPDATE
  • ACTION_ERROR - PaymentAction.ACTION_ERROR

API Independent Method Calls

These method calls don't require the payment to be in progress.

Getting Card Details:

checkCardDetails().subscribeOn(Schedulers.io())
                  .observeOn(AndroidSchedulers.mainThread())
                  .subscribeWith(new DisposableObserver<PaymentMethodsResponse>() {
                      @Override
                      public void onNext(PaymentMethodsResponse data) {
                          // Handle your card methdos response here
                      }

                      @Override
                      public void onError(Throwable e) {
                           // Handle your error card details here
                      }

                      @Override
                      public void onComplete() {

                      }
                  });

Getting Remove Card:

removeCard("123abc").subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeWith(new DisposableObserver<RemoveCardResponse>() {
                        @Override
                        public void onNext(RemoveCardResponse data) {
                            // Remove card success response
                        }

                        @Override
                        public void onError(Throwable e) {
                            // Remove card failure error response
                        }

                        @Override
                        public void onComplete() {

                        }
                    });

Getting an specific Card:

getCard("123abc").subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeWith(new DisposableObserver<CardDetails>() {
                    @Override
                    public void onNext(CardDetails data) {
                        // Handle your card details here
                    }

                    @Override
                    public void onError(Throwable e) {
                         // Handle your error card details here
                    }

                    @Override
                    public void onComplete() {

                    }
                });

Useful Documentation

Java Documentation

UML Class Diagram

You can’t perform that action at this time.