A library that will allow you to create smart payments using the YooKassa service
The main class through which we will work with the YooKassa API
private static final YooKassa YOO_KASSA = YooKassa.create(
10000,
"yourTokenHere"
);
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()
);
}
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();
}
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();
}
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();
}
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()
);
}
public static Refund createRefund(Payment payment, Amount amount) throws IOException {
return YOO_KASSA.createRefund(RefundCreateData.from(payment,amount));
}
public static Refund getRefund(@NotNull UUID refundId) throws IOException {
return YOO_KASSA.getRefund(refundId);
}
<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>
repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.DeelTer:YooKassaSDK:1.0.4'
}