Yandex.Money SDK for Java

This Java library contains classes that allows you to do payments using Yandex.Money public API.

License

License

Agreement on Use of the Yandex.Money API
Categories

Categories

Java Languages Dex General Purpose Libraries Utility
GroupId

GroupId

com.yandex.java
ArtifactId

ArtifactId

ym-java-epr-sdk
Last Version

Last Version

2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Yandex.Money SDK for Java
This Java library contains classes that allows you to do payments using Yandex.Money public API.
Project URL

Project URL

https://tech.yandex.ru/money/
Source Code Management

Source Code Management

https://github.com/yandex-money/yandex-money-sdk-java.git

Download ym-java-epr-sdk

How to add to project

<!-- https://jarcasting.com/artifacts/com.yandex.java/ym-java-epr-sdk/ -->
<dependency>
    <groupId>com.yandex.java</groupId>
    <artifactId>ym-java-epr-sdk</artifactId>
    <version>2.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.yandex.java/ym-java-epr-sdk/
implementation 'com.yandex.java:ym-java-epr-sdk:2.0'
// https://jarcasting.com/artifacts/com.yandex.java/ym-java-epr-sdk/
implementation ("com.yandex.java:ym-java-epr-sdk:2.0")
'com.yandex.java:ym-java-epr-sdk:jar:2.0'
<dependency org="com.yandex.java" name="ym-java-epr-sdk" rev="2.0">
  <artifact name="ym-java-epr-sdk" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.yandex.java', module='ym-java-epr-sdk', version='2.0')
)
libraryDependencies += "com.yandex.java" % "ym-java-epr-sdk" % "2.0"
[com.yandex.java/ym-java-epr-sdk "2.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.squareup.okhttp : okhttp jar 1.6.0
com.google.code.gson : gson jar 2.3
joda-time : joda-time jar 2.5

test (1)

Group / Artifact Type Version
org.testng : testng jar 6.8.7

Project Modules

There are no modules declared in this project.

YooMoney SDK for Java

Overview

This Java library contains classes that allows you to do payments and call other methods of YooMoney public API.

Requirements

The library uses:

Usage

Gradle Dependency (jCenter)

Download

To use the library in your project write this code to your build.gradle:

buildscript {
    repositories {
        jcenter()
    }
}

dependencies {
    compile 'com.yoo.money.api:yoomoney-sdk-java:7.2.23'
}

App Registration

To be able to use the library you: the first thing you need to do is to register your application and get your unique client id. To do that please follow the steps described on this page (also available in Russian).

Conception

All API methods are represented as classes in package com.yoo.money.api.methods.

Some methods require an unique id to get the response. To get it use API method instance-id passing your client id. Once obtained instance id can be used to perform those methods.

Do NOT request instance id every time you need to call an API method. Obtain it once, store it safely and reuse it in future requests.

Performing Request

To perform request from com.yoo.money.api.methods package you will need to use ApiClient. For your convenience there is default implementation of the ApiClient called DefaultApiClient. It is suitable for most cases. So the very first thing you need to do, is to create ApiClient.

The minimal implementation will look like this:

ApiClient client = new DefaultApiClient.Builder()
    .setClientId("your_client_id_here")
    .create();

If you want to perform a method that requires user's authentication you need request access token. The easiest way to do this is to get AuthorizationData from a client:

AuthorizationParameters parameters = new AuthorizationParameters.Builder()
    ...
    .create();
AuthorizationData data = client.createAuthorizationData(parameters);

Provided AuthorizationParameters allows you to set request parameters as described here. When created AuthorizationData will have URL and POST parameters for OAuth2 authorization.

To get the result from redirect uri you may want to use AuthorizationCodeResponse.parse(redirectUri) method. If successful the instance of AuthorizationCodeResponse will contain temporary authorization code that must be immediately exchanged for an access token:

// parse redirect uri from web browser
AuthorizationCodeResponse response = AuthorizationCodeResponse.parse(redirectUri);

if (response.error == null) {
    // try to get OAuth2 access token
    Token token = client.execute(new Token.Request(response.code, client.getClientId(), myRedirectUri, myClientSecret));
    if (token.error == null) {
        ... // store token.accessToken safely for future uses

        // and authorize client to perform methods that require user's authentication
        client.setAccessToken(token.accessToken);
    } else {
        handleAuthorizationError(token.error);
    }
} else {
    handleAuthorizationError(response.error);
}

Now you can perform any request with authorized client. For instance, if you want to get InstanceId you can do it like this:

InstanceId instanceId = client.execute(new InstanceId.Request(clientId));
// do something with instance id

Links

  1. YooMoney API (in English, in Russian)
  2. YooMoney Java SDK on Bintray

Versions

Version
2.0