Simulate and Reverse a Transaction

Learn about transactions, as well as how to simulate and reverse an authorization transaction.

Overview

A transaction is the process of making a payment. We can use a Marqeta payment card to make a payment. An authorization transaction request includes the authorization details provided by the user and generates an electronic message that contains information used for payment processing.

In this lesson, we’ll learn to simulate an authorization transaction and its reversal.

Simulate an authorization transaction

We can simulate an authorization transaction by making a POST request to the {BASE_URL}/simulate/authorization endpoint. This endpoint requires the card_token and other authorization details to accompany the request.

Note: This endpoint is only available within the sandbox, which is a test environment. It’s not available within our production environment. The purpose of it is to be able to test the cards, users, and other objects we create in the sandbox.

Request Parameters

Parameter

Type

Category

Description

card_token

string

required

Token of the card used in the transaction

Maximum length: 255 characters

amount

decimal

required

Transaction amount

mid

string

required

Identifier of the merchant involved in the transaction

Maximum length: 50 characters

network_fees

array

optional

Contains different types of fees charged against a transaction

webhook

object

optional

Used to post information to the endpoints in our environment asynchronously

cash_back_amount

decimal

optional

Cash amount in case the transaction simulates authorization to receive cash back from a POS system

is_pre_auth

boolean

optional

True to mark the amount as authorization only, otherwise False

Default value: False

pin

string

optional

A card's PIN, if relevant

Maximum length: 4 characters

card_options

object

optional

Contains information regarding card usage

card_acceptor

object

optional

Contains a description of the merchant

transaction_options

object

optional

Contains additional information regarding a transaction

Note: Please refer to this course’s appendix for details of the card_acceptor, card_options, transaction_options, network_fees, and webhook objects.

Line 4: We enter the value for the required parameter amount.

Line 5: We add an arbitrary number 123456789 for the mid attribute, since we’re only simulating a transaction in a test environment.

Line 6: We use the previously stored CARD_TOKEN value for card_token.

Note: You can enter values for the other optional parameters that are given in the table above.

Click the “Run” button in the code widget below to see the output.

Press + to interact
url = '{{BASE_URL}}simulate/authorization'
data = json.dumps({
"amount": "",
"mid": "123456789",
"card_token": "{{CARD_TOKEN}}"
})
response = requests.post(url, headers=headers, data=data)
printResponse(response)

When the code is executed successfully, the output displays the complete transaction object with all of the requested data fields. We also extract the token and amount values and store them as TRANSACTION_TOKEN and TRANSACTION_AMOUNT, respectively.

In case of failure, an appropriate error message is displayed.

Simulate a transaction reversal

We can simulate a reversal of an authorization transaction by making a POST request to the {BASE_URL}/simulate/reversal endpoint. This endpoint requires the values for original_transaction_token and amount to accompany the request. A reversal of the transaction returns the funds to the account from which the transaction was originally made. This is done when the hold placed on the funds by the authorization transaction is released.

Request Parameters

Parameter

Type

Category

Description

original_transaction_token

string

required

Token of the transaction we want to reverse

amount

decimal

required

Transaction amount

network_fees

array

optional

Contains different types of fees charged against a transaction

webhook

object

optional

Used to post information to the endpoints in our environment asynchronously

Note: Please refer to this course’s appendix for details of the network_fees and webhook objects.

Lines 4–5: We use the extracted values TRANSACTION_TOKEN and TRANSACTION_AMOUNT for the required parameters original_transaction_token and amount, respectively.

Note: You can also enter values for the other optional parameters that are given in the table above.

Click the “Run” button in the code widget below to see the output.

Press + to interact
url = '{{BASE_URL}}simulate/reversal'
data = json.dumps({
"original_transaction_token": "{{TRANSACTION_TOKEN}}",
"amount": "{{TRANSACTION_AMOUNT}}"
})
response = requests.post(url, headers=headers, data=data)
printResponse(response)

When the code is executed successfully, the output displays the complete transaction object with all of the requested data fields.

In case of failure, an appropriate error message is displayed.