• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created over 7 years ago
  • Updated 18 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Adyen Android Drop-in and Components

Checkout Android Logo

Adyen Android

Adyen Android allows you to accept in-app payments by providing you with the building blocks you need to create a checkout experience.

For an overview of how you can integrate with Adyen on Android check out the Documentation Website


DropIn Preview


Support

If you have a feature request, or spotted a bug or a technical problem, create a GitHub issue. For other questions, contact our support team.

Installation

The Components are available through Maven Central, you only need to add the Gradle dependency.

Migrate from v3

If you are upgrading from 3.x.x to a current release, check out our migration guide.

Import with Gradle

Import the Component module for the Payment Method you want to use by adding it to your build.gradle file. For example, for the Drop-in solution you should add:

implementation "com.adyen.checkout:drop-in:4.12.0"

For a Credit Card component you should add:

implementation "com.adyen.checkout:card:4.12.0"

Client Key

Drop-in and Components require a client key, that should be provided in the Configuration.Builder constructors.

Drop-in

The Drop-in is the implementation that handles the presentation of all available payment methods and the subsequent entry of a customer's payment details. It is initialized with the response of /paymentMethods, and provides everything you need to make an API call to /payments and /payments/details.

Usage

The Drop-in requires the response of the /paymentMethods endpoint to be initialized. To pass the response to Drop-in, decode the response to the PaymentMethodsApiResponse class.

You can provide the raw JSONObject to the SERIALIZER object to deserialize the data.

val paymentMethodsApiResponse = PaymentMethodsApiResponse.SERIALIZER.deserialize(jsonObject)

The Drop-in relies on you to implement the calls to your server. When calling /payments or /payments/details is required, it will trigger an intent to the DropInService which you need to extend. The data comes as a JSONObject that you can use to compose your final /payments call on your back end. After the call, you return a DropInServiceResult with a certain type, each type expects different parameters.

  • DropInServiceResult.Action - If the result contains an action object, return it in the actionJSON param to continue the payment flow.
  • DropInServiceResult.Finished - If there is no action the payment flow is finished, the result will be passed along.
  • DropInServiceResult.Error - If an error happened during the connection.
class YourDropInService : DropInService() {
   // Submitting a payment request
   override fun makePaymentsCall(paymentComponentJson: JSONObject): DropInServiceResult {
       // Your server should make a /payments call containing the `paymentComponentJson`
       // Create the `DropInServiceResult` based on the /payments response
       return DropInServiceResult.Action("action JSON object")
   }
   // Submitting additional payment details
   override fun makeDetailsCall(actionComponentJson: JSONObject): DropInServiceResult {
       // Your server should make a /payments/details call containing the `actionComponentJson`
       // Create the `DropInServiceResult` based on the /payments/details response
       return DropInServiceResult.Finished("Authorised")
   }
}

Don't forget to also add the service your manifest.

<service android:name=".YourDropInService"/>

Configure Drop-in:

// Optional, if you want to display the amount and currency. In this example, the Pay button will display 10 EUR.
val amount = Amount().apply {
    currency = "EUR"
    value = 10_00
}

val dropInConfiguration = DropInConfiguration.Builder(YourContext, YourDropInService::class.java, "YOUR_CLIENT_KEY")
    .setAmount(amount)
    .setShopperLocale(shopperLocale)
    .build()

Optional - Configure specific payment methods:

val cardConfiguration = CardConfiguration.Builder(YourContext, "YOUR_CLIENT_KEY")
    .build()

val dropInConfiguration = DropInConfiguration.Builder(YourContext, YourDropInService::class.java, "YOUR_CLIENT_KEY")
    // ...
    .addCardConfiguration(cardConfiguration)
    .build()

You can find an example on how to create the cardConfiguration in the Components section.

After serializing the payment methods and creating the configuration, the Drop-in is ready to be initialized. Just call the DropIn.startPayment() method. Optionally, you can pass a resultIntent to be launched after Drop-in finishes (for example, a ResultActivity).

//Optional. In this example, ResultActivity will be launched after Drop-in finishes
val resultIntent = Intent(YourContext, ResultActivity::class.java)

DropIn.startPayment(YourContext, paymentMethodsApiResponse, dropInConfiguration, resultIntent)

To handle the Drop-in result, call DropIn.handleActivityResult inside onActivityResult within the activity that initiated the payment (DropIn.startPayment). The result is obtained in the DropInResult wrapper class:

class CheckoutActivity : Activity() {
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        val dropInResult = DropIn.handleActivityResult(requestCode, resultCode, data) ?: return
        when (dropInResult) {
            is DropInResult.Finished -> handleFinished(dropInResult.result) // will not be called if a resultIntent was passed to DropIn.startPayment
            is DropInResult.Error -> handleError(dropInResult.reason)
            is DropInResult.CancelledByUser -> handleCancelled()
        }
    }
}

Additionally, if you specified a resultIntent when calling DropIn.startPayment, simply call DropIn.getDropInResultFromIntent inside onCreate within the newly launched activity:

class ResultActivity : Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val result = DropIn.getDropInResultFromIntent(intent)
    }
}

Components

In order to have more flexibility over the checkout flow, you can use our Components to present each payment method individually in your own Activity.

To do that you need the data of that specific payment method parsed to the PaymentMethod class, and to create the configuration object (check out the docs for a more detailed guide on how to initialize the CardConfiguration.Builder).

val cardConfiguration = CardConfiguration.Builder(context, "YOUR_CLIENT_KEY") .build()

val cardComponent = CardComponent.PROVIDER.get(this@YourActivity, paymentMethod, cardConfiguration)

Then you need to add the Component View to your layout.

<com.adyen.checkout.card.CardView 
        android:id="@+id/cardView"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"/>

Then, after the component is initialized, you can attach it to the view to start getting user data.

cardView.attach(cardComponent, this@YourActivity)

From this moment you will start receiving updates when the user inputs data. When the data is valid, you can send it to the /payments endpoint.

cardComponent.observe(this) { paymentComponentState ->
   if (paymentComponentState?.isValid == true) {
      // When the shopper proceeds to pay, pass the `paymentComponentState.data` to your server to send a /payments request
      sendPayment(paymentComponentState.data)
   }
}

ProGuard

If you use ProGuard or R8, you do not need to manually add any rules, as they are automatically embedded in the artifacts. Please let us know if you find any issues.

See also

License

This repository is open source and available under the MIT license. For more information, see the LICENSE file.

More Repositories

1

adyen-web

Adyen Web Drop-in and Components
TypeScript
183
star
2

adyen-magento2

Adyen Payment plugin for Magento2
PHP
155
star
3

adyen-php-api-library

Adyen API Library for PHP
PHP
153
star
4

adyen-ios

Adyen iOS Drop-in and Components
Swift
151
star
5

adyen-java-api-library

Adyen API Library for Java
Java
115
star
6

adyen-dotnet-api-library

Adyen API Library for .NET
C#
108
star
7

adyen-node-api-library

Adyen API Library for Node.js
TypeScript
104
star
8

adyen-salesforce-commerce-cloud

Salesforce Commerce Cloud (formerly Demandware)
JavaScript
91
star
9

adyen-openapi

OpenAPI specification for the Adyen APIs
67
star
10

adyen-python-api-library

Adyen API Library for Python
Python
59
star
11

adyen-components-js-sample-code

Sample code of Adyen Components
JavaScript
54
star
12

adyen-go-api-library

Adyen API Library for Go
Go
51
star
13

adyen-react-native

Adyen React Native
Kotlin
45
star
14

adyen-commercetools

commercetools-adyen-integration provides an integration between the commercetools and Adyen payment service provider based on the concept of Adyen Web Components.
JavaScript
45
star
15

adyen-ruby-api-library

Adyen API Library for Ruby
Ruby
44
star
16

lume

Lume is a component library for visual representations of data, built for Vue with D3.
TypeScript
43
star
17

adyen-postgres-partitioning

Functions to manage partitions in PostgreSQL with minimal impact for applications
PLpgSQL
35
star
18

adyen-barcoder-ios

Use Verifone Barcode scanner over MFi
Swift
30
star
19

adyen-cse-ios

[Deprecated] Sample code for client-side encryption on iOS
Objective-C
28
star
20

adyen-3ds2-android

26
star
21

adyen-hybris

Adyen Payment plugin for Hybris
Java
25
star
22

adyen-flutter

Dart
23
star
23

adyen-3ds2-js-utils

Helper functions to get 3DS 2.0 integrated on the front-end
JavaScript
22
star
24

adyen-cse-android

[Deprecated] Sample code for client-side encryption on Android
Java
21
star
25

adyen-shopware6

Adyen Payment plugin for Shopware 6
PHP
21
star
26

adyen-3ds2-ios

Objective-C
18
star
27

adyen-cse-web

[DEPRECATED] Client-side encryption on JavaScript
JavaScript
15
star
28

adyen-postman

Postman files for the Adyen APIs
Shell
15
star
29

adyen-prestashop

Adyen Payment plugin for Prestashop
PHP
14
star
30

feast-spark-offline-store

This repo contains a plugin for feast to run an offline store on Spark
Python
14
star
31

adyen-pos-mobile-ios

Adyen POS Mobile SDK for iOS enabling the integration of TapToPay and the NYC1 card reader.
HTML
12
star
32

adyen-shopware5

PHP
11
star
33

adyen-magento2-express-checkout

Adyen Magento 2 Express Checkout Module
PHP
10
star
34

adyen-terminal-api-ios

Adyen Terminal API for iOS
Swift
10
star
35

adyen-secured-fields-sample-code

JavaScript
9
star
36

adyen-salesforce-b2b-commerce

Adyen app for Salesforce B2B Commerce
Apex
9
star
37

adyen-web-sdk-sample-code

Sample code for Adyen Web SDK
PHP
7
star
38

adyen-magento2-hyva

PHP
7
star
39

adyen-salesforce-headless-commerce-pwa

B2C Commerce Headless Integration Composable Storefront
JavaScript
6
star
40

adyen-pos-mobile-android

Kotlin
5
star
41

adyen-integration-tools-tests

JavaScript
5
star
42

adyen-wechatpay-ios

Adyen WeChat Pay SDK Wrapper
Objective-C
5
star
43

adyen-networking-ios

Swift
5
star
44

php-webhook-module

PHP Webhook Helper Module for Adyen Payment Integrations
PHP
5
star
45

adyen-openapi-generator

Generate OpenApi models from Adyen Services APIs
JavaScript
5
star
46

adyen-authentication-ios

AdyenAuthentication SDK Provides reusable and easy to use two factor authentication for security sensitive use cases like banking, issuing and PSD2 strong customer authentication.
C++
4
star
47

adyen-document-viewer

Adyen Document Viewer
TypeScript
3
star
48

.github

Organization-wide community health files in the @adyen organization
3
star
49

adyen-testcards-android

Easily autofill Adyen test payment methods on Android.
Kotlin
2
star
50

adyen-salesforce-b2b-lightning

Salesforce B2B Commerce Lightning
Apex
2
star
51

adyen-apple-pay-provisioning-ios

Resources to help integrate Apple Pay Provisioning for Adyen issued card partners
C++
1
star
52

adyen-apex-api-library

Adyen API Library for Apex
Apex
1
star
53

release-automation-action

TypeScript
1
star