All Projects → yoomoney → yoomoney-sdk-java

yoomoney / yoomoney-sdk-java

Licence: MIT license
This Java library contains classes that allows you to do payments and call other methods of YooMoney public API

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to yoomoney-sdk-java

Donate-page
Таблица донатеров с авторизацией через VK и Discord и оплатой через Yoomoney и Qiwi p2p
Stars: ✭ 13 (-23.53%)
Mutual labels:  yoomoney
glQiwiApi
The ultrarapid and multifunctional wrapper over QIWI and YooMoney
Stars: ✭ 44 (+158.82%)
Mutual labels:  yoomoney
cms-prestashop
YooKassa payment module for PrestaShop
Stars: ✭ 13 (-23.53%)
Mutual labels:  yoomoney

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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].