SDK for Android
The library allows you to implement payment acceptance into Android mobile apps and acts as an extension to the Yandex.Checkout API.
Mobile SDK includes ready-made payment interfaces, such as the payment form and everything related to it. Using the SDK, you can receive tokens for processing payments made via bank cards, Google Pay, Sberbank Online, or the Yandex.Money wallet.
 Demo app
You can preview payment interfaces and the payment process in our special demo application. After installing the demo app, you will be able to experience the entire payment process from the point of view of your customers: click the Buy button, enter your bank card details or the Yandex.Money wallet details. The app allows you to play out different payment scenarios.
The app must be installed from a smartphone.
By downloading this demo app, you accept the license agreement.
 Using the SDK
First of all, you need to implement payment acceptance via the Yandex.Checkout API. After that:
  1. Tell the manager you want to process payments using the mobile SDK.
  2. Once mobile SDK is enabled, issue a key for it in the Integration — API keys section of your Merchant Profile.
  3. Add the SDK to the app and configure it to generate one-time payment tokens.
  4. Set up the process of sending one-time tokens from the mobile app to your system (for example, to the back-end of your website that interacts with Yandex.Checkout).
  5. Make payments using payment tokens via the Yandex.Checkout API.
 Implementing dependencies
To use the mobile SDK, implement dependencies via Gradle.
If you’re going to accept payments from Yandex.Checkout wallets or sell digital goods in the app, you will need to additionally configure the app.
 Implementing dependencies via Gradle
To implement the library, add dependencies in 
build.gradle
of your module.
Groovy
repositories {
    maven { url 'https://dl.bintray.com/yandex-money/maven' }
}

dependencies {
    implementation 'com.yandex.money:checkout:$versionName'
}
 Configuring the app to accept payments from Yandex.Money wallets
To accept payments made for Yandex.Money wallets, you’ll need Yandex authorization.
  1. Register your app in Yandex.OAuth and save the ID. During the registration:
  2. enter the app’s name;
  3. select Android app in the Platforms section and fill out the settings for Android;
  4. select Access to login, first name and surname, gender in the Yandex.Passport API so the user’s name will display properly.
  5. Implement
    YandexLoginSDK
    .
Groovy
android {
    defaultConfig {
        manifestPlaceholders = [YANDEX_CLIENT_ID:"your app's ID in Yandex.OAuth"]
    }
}
repositories {
    mavenCentral()
}
dependencies {
    implementation "com.yandex.android:authsdk:$authsdkVersion"
}
 Configuring the app to sell digital goods
If you use the app to sell digital goods, disable Google Pay (it doesn’t allow payments for software and other products) by adding the corresponding code to AndroidManifest.
Java
<meta-data
    android:name="com.google.android.gms.wallet.api.enabled"
    tools:node="remove" />
 Using SDK
The working process consists of calls to the
ru.yandex.money.android.sdk.Checkout
class.
Using the SDK, you can:
You can also test data tokenization.
 Tokenization
 Step 1. Tokenization launch
To start tokenization, call the
Checkout.createTokenizeIntent ()
method. It will respond with
Intent
that you’ll need to launch in 
startActivityForResult ()
. Mobile SDK will manage the process after that.
Java
class MyActivity extends android.support.v7.app.AppCompatActivity {

    ...

    void timeToStartCheckout() {
        PaymentParameters paymentParameters = new PaymentParameters(
                new Amount(BigDecimal.TEN, Currency.getInstance("RUB")),
                "Product name",
                "Product description",
                "live_AAAAAAAAAAAAAAAAAAAA",
                "12345"
        );
        Intent intent = Checkout.createTokenizeIntent(this, paymentParameters);
        startActivityForResult(intent, REQUEST_CODE_TOKENIZE);
    }
}
Method’s input parameters
ParameterTypeDescription
context
ContextApp context
paymentParameters
PaymentParametersPayment parameters
testParameters
TestParametersDebugging parameters
uiParameters
UiParametersInterface parameters
PaymentParameters fields
Required PaymentParameters fields
ParameterTypeDescription
amount
AmountObject containing the payment amount and currency.
title
StringProduct name.
subtitle
StringProduct description.
clientApplicationKey
StringClient apps key from the Integration — API keys section of your Merchant Profile.
shopId
StringStore’s ID in Yandex.Checkout.
Optional PaymentParameters fields
ParameterTypeDescription
paymentMethodTypes
PaymentMethodTypePayment methods available to users in the app. If you leave the field empty or specify
null
, mobile SDK will use all available payment methods.
gatewayId
StringSubaccount ID. Used for dividing payment flows within one account. Optional parameter.
customReturnUrl
StringURL of the page for returning after 3-D Secure. HTTPS only. Parameter is mandatory only if you use your own Activity for 3-D Secure implementation. If you use Activity of the mobile SDK, don’t specify this parameter.
userPhoneNumber
StringUser’s phone number for payments via Sberbank Online. Used for automatic filling out of the payment form. Format: “+7XXXXXXXXXX”.
googlePayParameters
GooglePayParametersConfiguration for payments via Google Pay
Amount class fields
ParameterTypeDescription
value
BigDecimalOrder amount. Maximum and minimum values depend on the selected payment method and the settings of your Yandex.Checkout Merchant Profile.
currency
CurrencyCurrency.
PaymentMethodType values
  • YANDEX_MONEY
    — Yandex.Money (payments from wallets or linked bank cards);
  • BANK_CARD
    — bank cards (can be scanned);
  • SBERBANK
    — Sberbank Online (with payment confirmation via text message);
  • GOOGLE_PAY
    — Google Pay.
GooglePayParameters class fields
ParameterTypeDescription
allowedCardNetworks
Set (GooglePayCardNetwork)Payment systems whose cards are allowed for payments via Google Pay in your app. Possible values:
MASTERCARD
,
VISA
,
AMEX
,
DISCOVER
,
JCB
,
INTERAC
,
OTHER
 Step 2. Tokenization results
Tokenization results will be returned in 
onActivityResult ()
. Possible result codes (
resultCode
):
  • Activity.RESULT_OK
    — tokenization is successful;
  • Activity.RESULT_CANCELED
    — user canceled tokenization.
If tokenization is successful, SDK will return the payment token and payment method. To get a token, call the
Checkout.createTokenizationResult ()
method and use
Intent
from
onActivityResult ()
in it.
Java
public final class MainActivity extends AppCompatActivity {

    ...

     @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

            if (requestCode == REQUEST_CODE_TOKENIZE) {
                switch (resultCode) {
                    case RESULT_OK:
                        // successful tokenization
                        TokenizationResult result = Checkout.createTokenizationResult(data);
                        ...
                        break;
                    case RESULT_CANCELED:
                        // user canceled tokenization
                        ...
                        break;
                }
            }
        }
}
Checkout.createTokenizationResult ()
returns
TokenizationResult
.
TokenizationResult parameters
ParameterTypeDescription
paymentToken
StringPayment token.
paymentMethodType
PaymentMethodTypePayment method.
PaymentMethodType
values:
  • YANDEX_MONEY
    — Yandex.Money (payments from wallets or linked bank cards);
  • BANK_CARD
    — bank cards;
  • SBERBANK
    — Sberbank Online (with payment confirmation via text message);
  • GOOGLE_PAY
    — Google Pay.
 Test parameters and tokenization debugging
You can debug tokenization using test mode and logging.
Test mode allows checking the SDK processes without real data. You can see how the SDK works in various conditions and generate a test token. Mobile SDK doesn’t require Internet connection in test mode.
Test token can’t be used for real payments.
Mobile SDK logs all transactions. You can enable the logs display for real and test payments. All logs start with the 'Yandex.Checkout.SDK' tag.
For tokenization debugging, call
Checkout.createTokenizeIntent ()
with the
TestParameters
object.
Java
class MyActivity extends android.support.v7.app.AppCompatActivity {

    ...

    void timeToStartCheckout() {
        PaymentParameters paymentParameters = new PaymentParameters(...);
        TestParameters testParameters = new TestParameters(true, true, new MockConfiguration(false, true, 5));
        Intent intent = Checkout.createTokenizeIntent(this, paymentParameters, testParameters);
        startActivityForResult(intent, REQUEST_CODE_TOKENIZE);
    }
}
TestParameters
class fields:
ParameterTypeDescription
showLogs
BooleanDisplaying logs for mobile SDK.
mockConfiguration
MockConfigurationTest configuration settings. If this parameter is specified, mobile SDK will work in offline mode and generate a test token.
MockConfiguration
class fields:
ParameterTypeDescription
completeWithError
BooleanTokenization always returns an error.
paymentAuthPassed
BooleanUser is always authorized.
linkedCardsCount
IntNumber of cards linked to user’s wallet.
 Interface configuration
You can configure the mobile SDK interface using the
UiParameters
object.
UiParameters
class fields:
ParameterTypeDescription
showLogo
BooleanShow or hide the Yandex.Checkout logo on the screen with payment methods.
colorScheme
ColorSchemeApp’s color scheme.
ColorScheme
class fields:
ParameterTypeDescription
primaryColor
ColorIntPrimary color to be used as background for buttons and other interface elements. We recommend not to select overly bright shades (the app has a white background, and bright interface elements will be lost) and color red (it signifies an error).
Java
class MyActivity extends android.support.v7.app.AppCompatActivity {

    ...

    void timeToStartCheckout() {
        PaymentParameters paymentParameters = new PaymentParameters(...);
        UiParameters uiParameters = new UiParameters(true, new ColorScheme(Color.rgb(0, 114, 245)));
        Intent intent = Checkout.createTokenizeIntent(this, paymentParameters, new TestParameters(), uiParameters);
        startActivityForResult(intent, REQUEST_CODE_TOKENIZE);
    }
}
 3-D Secure
Mobile SDK has Activity for processing 3-D Secure:
Checkout.create3dsIntent ()
.
If you process 3-D Secure via Activity of the mobile SDK, don’t specify
PaymentParameters.customReturnUrl
when calling
Checkout.createTokenizeIntent ()
.
Input parameters for
Checkout.create3dsIntent ()
:
ParameterTypeDescription
context
ContextContext for creating
Intent
.
url
StringURL for proceeding to 3-D Secure.
colorScheme
ColorSchemeColor scheme.
You can get the results of 3-D Secure processing in 
onActivityResult ()
. Possible result codes (
resultCode
):
  • Activity.RESULT_OK
    — authentication via 3-D Secure is successful;
  • Activity.RESULT_CANCELED
    — 3-D Secure screen was closed (for example, the user clicked the Back button);
  • Checkout.RESULT_ERROR
    — unable to complete authentication via 3-D Secure.
Java
class MyActivity extends android.support.v7.app.AppCompatActivity {

    void timeToStart3DS() {
        Intent intent = Checkout.create3dsIntent(
                this,
                "https://3dsurl.com/"
        );
        startActivityForResult(intent, 1);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == 1) {
            switch (resultCode) {
                case RESULT_OK:
                    // Authentication via 3-D Secure is successful
                    break;
                case RESULT_CANCELED:
                    // 3-D Secure screen was closed
                    break;
                case Checkout.RESULT_ERROR:
                    // Error during 3-D Secure authorization
                    //(for example, connection error),
                    // you can find more detailed information in data:
                    // data.getIntExtra(Checkout.EXTRA_ERROR_CODE) — error code from WebViewClient.ERROR_* or Checkout.ERROR_NOT_HTTPS_URL
                    // data.getStringExtra(Checkout.EXTRA_ERROR_DESCRIPTION) — error description (may be missing)
                    // data.getStringExtra(Checkout.EXTRA_ERROR_FAILING_URL) — URL where the error occured (may be missing)
                    break;
            }
        }
    }
}
 Scanning bank cards
Create
Activity
processing the
ru.yandex.money.android.sdk.action.SCAN_BANK_CARD
action.
XML
<activity android:name=".ScanBankCardActivity">

    <intent-filter>
        <action android:name="ru.yandex.money.android.sdk.action.SCAN_BANK_CARD"/>
    </intent-filter>

</activity>
Launch the library for scanning bank cards in this
Activity
. Send the received number in 
Intent
.
If the scanning was successful, specify
Activity.RESULT_OK
.
Java
public class ScanBankCardActivity extends Activity {

    private void onScanningDone(final String cardNumber, final int expirationMonth, final int expirationYear) {

        final Intent result = Checkout.createScanBankCardIntent(cardNumber, expirationMonth, expirationYear);

        setResult(Activity.RESULT_OK, result);

        finish();

    }

}
 See also
Payment tokenPayment processPayment methodsNotifications