Payments
Payments is a task pack that takes a card payment the caller agreed to, and the
model never hears the card. Add it to an Operations or a
ServiceAgent with add_to().
- The caller says what they’re paying, such as an invoice number.
- Your
chargefunction returns the amount. The amount never comes from the model. - The amount is read back for the caller’s yes.
- The platform’s
payverb takes the card on the keypad and charges it through your payment connector. - The model is told to call the result tool, which reads the outcome the platform recorded. A payment that went through is added to the call’s record with its money.
In a chat, the payment tool says a payment is taken on a call, and nothing changes.
The pack adds pay_result and pay_payment_results to the agent’s
swaig_post_swml_vars param. The card prompts need a language: language=, or the
agent’s first language from add_language(). Without either, the agent
raises ValueError when it’s set up. A payment also needs a currency, from the
Charge, the pack, or the service.
Parameters
All parameters are keyword-only.
connector_url
Your payment connector, which the platform sends the card to. An empty value raises
ValueError.
charge
currency
ISO 4217 code of the amounts. Defaults to the service’s currency.
language
Language code for the platform’s card prompts, such as "en-US". Defaults to the
agent’s first language.
voice
Voice for the card prompts. Defaults to the voice of the agent’s first language.
security_code
Whether the card’s security code is asked for.
postal_code
Whether the billing postal code is asked for.
max_attempts
How many times the caller may try the card.
reusable
True asks for a reusable token the connector can charge again, in place of a
one-time token.
card_types
Card types taken, such as ["visa", "mastercard"]. None takes Visa, Mastercard,
and American Express.
status_url
Where the platform posts each step of the payment.
connector_parameters
More name/value pairs sent to the connector.
on_result
on_result(call, result) receives every PaymentResult, for your records. May be
async.
before_identity
True to take payments from callers who aren’t identified.
tool
The payment tool’s name.
result_tool
The result tool’s name.
wording
Replacements keyed like PAYMENTS_WORDING. See wording.
state_key
Where in call.state the payment under way is kept.
Methods
add_to(target) registers the pack’s operations on an Operations or a
ServiceAgent, and returns target.
Charge
A frozen dataclass that charge returns.
Charge.amount
How much to charge: more than 0.
Charge.description
What it’s for, as it’s said: “invoice 1042, for March”.
Charge.currency
Its ISO 4217 code. Defaults to the pack’s, then the service’s.
PaymentResult
A frozen dataclass that on_result receives.
PaymentResult.result
The platform’s pay_result, such as success, too-many-failed-attempts,
payment-connector-error, caller-interrupted-with-star, caller-hung-up,
validation-error, or internal-error.
PaymentResult.amount
The amount charged or attempted.
PaymentResult.currency
The amount’s ISO 4217 code.
PaymentResult.description
What the payment was for, from the Charge.
PaymentResult.paying_for
What the caller said they were paying, as charge received it.
PaymentResult.details
The platform’s pay_payment_results: the token, confirmation code, and masked card,
when there are any.
PaymentResult.succeeded
True when result is success.