Package tech.mogami.java.client.helper
Class X402PaymentHelper
java.lang.Object
tech.mogami.java.client.helper.X402PaymentHelper
This class provides helper methods for handling X402 payments.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic tech.mogami.commons.header.payment.PaymentPayloadgetPayloadFromPaymentRequirements(String signature, @NonNull String fromAddress, @NonNull tech.mogami.commons.header.payment.PaymentRequirements paymentRequirements) Generate a PaymentPayload from a specific PaymentRequirements WITHOUT SIGNATURE.static StringgetPayloadHeader(@NonNull tech.mogami.commons.header.payment.PaymentPayload paymentPayload) Encodes the PaymentPayload into a Base64 string to be used as X-PAYMENT header.static Optional<tech.mogami.commons.header.payment.PaymentRequired> getPaymentRequiredFromBody(String xPaymentHeader) Parses the X-Payment body and returns a PaymentRequired object.static Optional<tech.mogami.commons.api.facilitator.settle.SettleResponse> getSettleResponseFromHeader(String xPaymentResponseHeader) Decodes the X-PAYMENT-RESPONSE header and returns a SettleResponse object.static tech.mogami.commons.header.payment.PaymentPayloadgetSignedPayload(@NonNull org.web3j.crypto.Credentials credentials, @NonNull tech.mogami.commons.header.payment.PaymentRequirements paymentsRequirements, @NonNull tech.mogami.commons.header.payment.PaymentPayload paymentPayload) Generate a PaymentPayload from a specific PaymentRequirements with signature.
-
Constructor Details
-
X402PaymentHelper
public X402PaymentHelper()
-
-
Method Details
-
getPaymentRequiredFromBody
public static Optional<tech.mogami.commons.header.payment.PaymentRequired> getPaymentRequiredFromBody(String xPaymentHeader) Parses the X-Payment body and returns a PaymentRequired object.- Parameters:
xPaymentHeader- The value of the X-Payment header.- Returns:
- A PaymentRequired object containing the parsed payment requirements.
-
getPayloadFromPaymentRequirements
public static tech.mogami.commons.header.payment.PaymentPayload getPayloadFromPaymentRequirements(String signature, @NonNull @NonNull String fromAddress, @NonNull @NonNull tech.mogami.commons.header.payment.PaymentRequirements paymentRequirements) Generate a PaymentPayload from a specific PaymentRequirements WITHOUT SIGNATURE.- Parameters:
signature- The signature of the payment payload.fromAddress- The address from which the payment is made.paymentRequirements- The payment requirements to convert.- Returns:
- A PaymentPayload object containing the payment details.
-
getSignedPayload
public static tech.mogami.commons.header.payment.PaymentPayload getSignedPayload(@NonNull @NonNull org.web3j.crypto.Credentials credentials, @NonNull @NonNull tech.mogami.commons.header.payment.PaymentRequirements paymentsRequirements, @NonNull @NonNull tech.mogami.commons.header.payment.PaymentPayload paymentPayload) Generate a PaymentPayload from a specific PaymentRequirements with signature.- Parameters:
credentials- the credentials of the user making the paymentpaymentsRequirements- the payment requirements to convertpaymentPayload- the payment payload to sign- Returns:
- A PaymentPayload object containing the signed payment details.
-
getPayloadHeader
public static String getPayloadHeader(@NonNull @NonNull tech.mogami.commons.header.payment.PaymentPayload paymentPayload) Encodes the PaymentPayload into a Base64 string to be used as X-PAYMENT header.- Parameters:
paymentPayload- The PaymentPayload to encode.- Returns:
- A Base64 encoded string representation of the PaymentPayload.
-
getSettleResponseFromHeader
public static Optional<tech.mogami.commons.api.facilitator.settle.SettleResponse> getSettleResponseFromHeader(String xPaymentResponseHeader) Decodes the X-PAYMENT-RESPONSE header and returns a SettleResponse object.- Parameters:
xPaymentResponseHeader- The Base64 encoded X-PAYMENT-RESPONSE header.- Returns:
- A SettleResponse object if the header is not empty, otherwise null.
-