From 2f11be45dd8bd995c6e3b4c9bc446f64e8497a35 Mon Sep 17 00:00:00 2001 From: Joao Pedro Truchinski Borba Date: Sat, 6 Apr 2024 22:06:26 -0300 Subject: [PATCH] feat: qr code paying --- docs/pix_transaction.md | 10 +++++ .../io/github/jpdev/asaassdk/http/Domain.java | 1 + .../rest/pix/transaction/PixTransaction.java | 4 ++ .../PixTransactionQrCodeCreator.java | 39 +++++++++++++++++++ .../rest/pix/transaction/children/QrCode.java | 15 +++++++ 5 files changed, 69 insertions(+) create mode 100644 src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransactionQrCodeCreator.java create mode 100644 src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/children/QrCode.java diff --git a/docs/pix_transaction.md b/docs/pix_transaction.md index cff62b9..b84b8d9 100644 --- a/docs/pix_transaction.md +++ b/docs/pix_transaction.md @@ -39,6 +39,16 @@ Transfer transfer = Transfer.pixManualCreator() .create(); ``` +## Pagar um QR Code Pix +```java +final String examplePayload = "00020101021226730014br.gov.bcb.pix2551pix-h.asaas.com/pixqrcode/cobv/pay_76575613967995145204000053039865802BR5905ASAAS6009Joinville61088922827162070503***63045E7A"; +PixTransaction pixTransactionQrCodeCreator = PixTransaction + .qrCodeCreator() + .setPayload(examplePayload) + .setValue(Money.create(new BigDecimal(10.0))) + .create(); +``` + ## Listar transações Pix ```java ResourceSet pixTransactionResourceSet = PixTransaction.reader().read(); diff --git a/src/main/java/io/github/jpdev/asaassdk/http/Domain.java b/src/main/java/io/github/jpdev/asaassdk/http/Domain.java index 14a173d..a5f7de2 100644 --- a/src/main/java/io/github/jpdev/asaassdk/http/Domain.java +++ b/src/main/java/io/github/jpdev/asaassdk/http/Domain.java @@ -9,6 +9,7 @@ public enum Domain { REFUND_PAYMENT("payments/$id/refund"), PIX_TRANSACTION("pix/transactions"), PIX_TRANSACTION_CANCELLATION("pix/transactions/$id/cancel"), + PIX_TRANSACTION_QR_CODE("pix/qrCodes/pay"), PIX_ADDRESS_KEY("pix/addressKeys"), STATIC_PIX_QR_CODE("pix/qrCodes/static"), DECODE_PIX_QR_CODE("pix/qrCodes/decode"), diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransaction.java b/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransaction.java index 5860b5f..75b58b4 100644 --- a/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransaction.java +++ b/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransaction.java @@ -55,4 +55,8 @@ public static PixTransactionCanceller canceller(String id) { public static PixTransactionFetcher fetcher(Object id) { return new PixTransactionFetcher(id); } + + public static PixTransactionQrCodeCreator qrCodeCreator() { + return new PixTransactionQrCodeCreator(); + } } diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransactionQrCodeCreator.java b/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransactionQrCodeCreator.java new file mode 100644 index 0000000..af6044d --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/PixTransactionQrCodeCreator.java @@ -0,0 +1,39 @@ +package io.github.jpdev.asaassdk.rest.pix.transaction; + +import io.github.jpdev.asaassdk.http.Domain; +import io.github.jpdev.asaassdk.rest.action.Creator; +import io.github.jpdev.asaassdk.rest.pix.transaction.children.QrCode; + +import java.math.BigDecimal; + +public class PixTransactionQrCodeCreator extends Creator { + + private QrCode qrCode; + private BigDecimal value; + + public BigDecimal getValue() { + return value; + } + + public PixTransactionQrCodeCreator setValue(BigDecimal value) { + this.value = value; + return this; + } + + public PixTransactionQrCodeCreator setPayload(String payload) { + this.qrCode = new QrCode().setPayload(payload); + return this; + } + + public QrCode getQrCode() { + return qrCode; + } + + public String getResourceUrl() { + return Domain.PIX_TRANSACTION_QR_CODE.toString(); + } + + public Class getResourceClass() { + return PixTransaction.class; + } +} diff --git a/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/children/QrCode.java b/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/children/QrCode.java new file mode 100644 index 0000000..4c7371c --- /dev/null +++ b/src/main/java/io/github/jpdev/asaassdk/rest/pix/transaction/children/QrCode.java @@ -0,0 +1,15 @@ +package io.github.jpdev.asaassdk.rest.pix.transaction.children; + +public class QrCode { + + public String payload; + + public String getPayload() { + return payload; + } + + public QrCode setPayload(String payload) { + this.payload = payload; + return this; + } +}