DeelTer / YooKassaSDK

YooKassa API
11 stars 2 forks source link

YooKassa SDK

A library that will allow you to create smart payments using the YooKassa service

API Initialization

The main class through which we will work with the YooKassa API

private static final YooKassa YOO_KASSA = YooKassa.create(
        10000,
        "yourTokenHere"
        );

Payment creation

public static Payment createPayment() throws IOException {
    return YOO_KASSA.createPayment(PaymentCreateData.builder()
                .amount(Amount.from(100, Currency.RUB))
                .description("Buy a coffee")
                .redirect("https://github.com/deelter")
                .capture(true)
                .build()
    );
}

Payment information

public static Payment getPayment(UUID paymentId) throws IOException {
    return YOO_KASSA.getPayment(paymentId);
}

// Is payment status success
public static boolean isSuccess(UUID paymentId) throws IOException {
    return getPayment(paymentId).getStatus().isSuccess();
}

Receipts

Customer

The buyer (client) must be registered in the object of the receipt

public static Customer createCustomer(String email, String phone) {
    return Customer.builder()
        .email(email)
        .phone(phone)
        .build();
}

Items

The receipt object can contain either one or several items

public static ReceiptItem createReceiptItem() {
    return ReceiptItem.builder()
        .description("Serious hat")
        .amount(Amount.from(50, Currency.RUB))
        .quantity(1)
        .vatCode(1)
        .build();
}

Receipt integration

public static Payment createPaymentWithReceipt(Receipt receipt)throws IOException{
    return YOO_KASSA.createPayment(PaymentCreateData.builder()
                    .amount(Amount.from(50, Currency.RUB))
                    .description("Serious chest")
                    .redirect("https://github.com/deelter")
                    .capture(true)
                    .receipt(receipt)
                    .build()
        );
}

Refunds

Refund creation

public static Refund createRefund(Payment payment, Amount amount) throws IOException {
    return YOO_KASSA.createRefund(RefundCreateData.from(payment,amount));
}

Getting refund object

public static Refund getRefund(@NotNull UUID refundId) throws IOException {
    return YOO_KASSA.getRefund(refundId);
}

Download

Maven


<repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
</repository>

<dependency>
    <groupId>com.github.DeelTer</groupId>
    <artifactId>YooKassaSDK</artifactId>
    <version>1.0.4</version>
</dependency>

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    implementation 'com.github.DeelTer:YooKassaSDK:1.0.4'
}