Payment Gateway Agent

API Reference

Mercoa’s payment gateway agent enables you to seamlessly detect and take action on opportunities to convert a non-card payment to card spend from an invoice document.

Agent Actions

Mercoa’s payment gateway agent can perform the following actions:

  • Validate that an invoice contains a card-supporting payment gateway link
  • Process a card payment by running a provided card through the payment gateway

Each action is triggered by the corresponding API endpoint.

Usage

To start using the payment gateway agent, all you need to have is the invoice document or email (PDF or HTML).

Validation

First, upon receiving an invoice, you can trigger a validation job with the invoice document to determine if a card conversion is possible.

POST
/payment-gateway/validate
1from mercoa import Mercoa
2from mercoa.payment_gateway_types import ValidatePaymentGatewayRequest_Document
3
4client = Mercoa(
5 token="YOUR_TOKEN",
6)
7client.payment_gateway.create_validation_job(
8 request=ValidatePaymentGatewayRequest_Document(
9 document="ValidatePaymentGatewayRequestDocument.Default",
10 ),
11)

Upon successful completion, the result of the validation job will contain the following information:

  • The extracted payment gateway link (if found)
  • Whether the payment gateway supports card
  • The associated card processing fees (if applicable)
  • A session replay link to review the agent’s actions
GET
/payment-gateway/validate/:jobId
1from mercoa import Mercoa
2
3client = Mercoa(
4 token="YOUR_TOKEN",
5)
6client.payment_gateway.get_validation_job(
7 job_id="job_1a92b5f7-f522-435e-a953-fd649363730a",
8)
1{
2 "jobStatus": "completed",
3 "jobId": "job_1a92b5f7-f522-435e-a953-fd649363730a",
4 "card": {
5 "eligibility": "ACCEPTED",
6 "fee": {
7 "type": "percentage",
8 "value": 2.5
9 }
10 },
11 "paymentGatewayUrl": "https://www.payment-gateway.com/invoice/job_1a92b5f7-f522-435e-a953-fd649363730a",
12 "sessionUrl": "https://www.payment-gateway.com/session/job_1a92b5f7-f522-435e-a953-fd649363730a"
13}

Processing

Once you’ve identified an invoice that supports card spend, you can process the payment triggering a processing job with the invoice document and details of the card to be used for the payment.

POST
/payment-gateway/process
1from mercoa import Mercoa
2from mercoa.payment_gateway_types import (
3 ProcessPaymentGatewayCardDetails_Iframe,
4 ProcessPaymentGatewayRequest_Html,
5)
6
7client = Mercoa(
8 token="YOUR_TOKEN",
9)
10client.payment_gateway.create_process_job(
11 request=ProcessPaymentGatewayRequest_Html(
12 html='<html><body><h1>Invoice Details</h1><a href="https://www.payment-gateway.com/invoice/123123">Pay Invoice</a></body></html>',
13 card_details=ProcessPaymentGatewayCardDetails_Iframe(
14 iframe_url="https://www.myvirtualcard.com/iframe/543543",
15 ),
16 ),
17)

We recommend that you provide card details via an iFrame link rather than directly in the request body to avoid exposing sensitive data.

Upon successful completion, the result of the processing job will contain the following information:

  • The receipt URL for the payment
  • A session replay link to review the agent’s actions

If the agent is unable to process the payment, no funds will be moved and the result will contain a descriptive error message explaining what went wrong.

GET
/payment-gateway/process/:jobId
1from mercoa import Mercoa
2
3client = Mercoa(
4 token="YOUR_TOKEN",
5)
6client.payment_gateway.get_process_job(
7 job_id="job_1a92b5f7-f522-435e-a953-fd649363730a",
8)
1{
2 "jobStatus": "completed",
3 "jobId": "job_1a92b5f7-f522-435e-a953-fd649363730a",
4 "receiptUrl": "https://www.payment-gateway.com/receipt/123123",
5 "sessionUrl": "https://www.payment-gateway.com/session/job_1a92b5f7-f522-435e-a953-fd649363730a"
6}