Class AfterpayTools

java.lang.Object
com.tnsai.tools.fintech.AfterpayTools

public class AfterpayTools extends Object
Function-shape Afterpay tools — the LangChain-style replacement for the legacy AfterpayCheckoutTool. Buy-Now-Pay-Later (4-installment) checkout via Afterpay's global API (https://developers.afterpay.com).

Three typed @Tool methods covering the most-common Afterpay operations:

MethodEndpointIdempotent
afterpayCreateCheckout(long, java.lang.String, java.lang.String, java.lang.String, java.lang.String)POST /v2/checkouts✓
afterpayCapturePayment(java.lang.String)POST /v2/payments/capture✗ (real money move)
afterpayGetOrder(java.lang.String)GET /v2/orders/{id}✓

Auth: HTTP Basic with the merchant id + secret key the consumer obtains at https://developers.afterpay.com. Sandbox routing via useSandbox=true (or AFTERPAY_SANDBOX=true env).

Afterpay enforces a per-region order amount range — typically $1.00 to $2,000 for AU/US/CA — that varies by merchant agreement. The POJO enforces the minimum $1.00 guard locally; everything above is left to Afterpay's HTTP response.

Since:
0.5.7 (Phase 2 batch 7c — built-in tool migration to function shape, see #188)
  • Constructor Details

    • AfterpayTools

      public AfterpayTools()
      Default constructor — reads AFTERPAY_MERCHANT_ID + AFTERPAY_SECRET_KEY + AFTERPAY_SANDBOX from env.
    • AfterpayTools

      public AfterpayTools(String merchantId, String secretKey, boolean useSandbox)
      Explicit credentials + sandbox flag.
    • AfterpayTools

      public AfterpayTools(String merchantId, String secretKey, boolean useSandbox, okhttp3.OkHttpClient http, com.fasterxml.jackson.databind.ObjectMapper mapper)
      Full constructor for tests / shared HTTP.
  • Method Details

    • afterpayCreateCheckout

      @Tool(name="afterpay_create_checkout", description="DESTRUCTIVE: create an Afterpay BNPL checkout session. Returns a {token, expiresAt, redirectCheckoutUrl} struct \u2014 redirect the customer to redirectCheckoutUrl to complete underwriting + payment selection in 4 installments. {amountCents} must be \u2265 100 (Afterpay\'s global minimum is $1 / \u00a31 / \u20ac1). {confirmUrl} and {cancelUrl} are merchant-side return URLs. The created checkout is in AUTHORISED status pending capture.", keywords={"afterpay","bnpl","buy-now-pay-later","checkout","installment","fintech","clearpay"}, idempotent=true) public Map<String,Object> afterpayCreateCheckout(@ToolParam(description="Order amount in smallest currency unit (1000 = $10.00 USD)") long amountCents, @ToolParam(description="ISO 4217 currency (\"USD\", \"AUD\", \"GBP\", \"NZD\", \"CAD\", \"EUR\")",required=false,defaultValue="USD") String currency, @ToolParam(description="Merchant-side reference (order number / cart id); blank lets Afterpay assign one",required=false,defaultValue="") String reference, @ToolParam(description="URL Afterpay redirects to on success \u2014 required by Afterpay\'s API") String confirmUrl, @ToolParam(description="URL Afterpay redirects to on cancel \u2014 required by Afterpay\'s API") String cancelUrl) throws IOException
      Throws:
      IOException
    • afterpayCapturePayment

      @Tool(name="afterpay_capture_payment", description="DESTRUCTIVE: capture (settle) an authorised Afterpay payment using the {token} returned from afterpay_create_checkout. This is a REAL money movement \u2014 Afterpay credits the merchant and starts the customer\'s 4-installment schedule. NOT idempotent at Afterpay\'s side; the framework\'s retry layer must NOT re-issue this call on transient failures. Returns {id, token, status, amount, currency}.", keywords={"afterpay","capture","settle","payment"}) public Map<String,Object> afterpayCapturePayment(@ToolParam(description="Checkout token returned from afterpay_create_checkout") String token) throws IOException
      Throws:
      IOException
    • afterpayGetOrder

      @Tool(name="afterpay_get_order", description="Read the current state of an Afterpay order \u2014 read-only. {orderId} is the id returned by afterpay_capture_payment. Returns {id, token, status, amount, currency, merchantReference}. Status \u2208 {AUTHORISED, CAPTURED, VOIDED, REFUNDED}.", keywords={"afterpay","order","status","read"}, idempotent=true) public Map<String,Object> afterpayGetOrder(@ToolParam(description="Afterpay order id (returned from afterpay_capture_payment)") String orderId) throws IOException
      Throws:
      IOException