Cancel a Transaction
This code steps you through the process of cancelling a credit card transaction.
You can cancel a transaction if it has not yet been settled. If a transaction has already been settled, then you must issue a refund instead.
For that Go to: Reverse a sale
This code cancels single transactions; it doesn't cancel recurring payments.
For that Go to: Cancel recurring payments
There are three outcomes when processing credit card transactions:
'Approved' transactions can be canceled. 'Declined' transactions cannot be canceled. As a result, in order to test the cancellation of a transaction, you must first pass an odd dollar amount. This will return the transaction with an 'Approved' status. Now, you can test the cancellation of that transaction.
An error could result from a variety of conditions such as missing data, invalid card numbers, and expiration dates provided in invalid formats.
# BluePay Python Sample code.
# This code sample runs a $3.00 Credit Card Sale transaction
# against a customer using test payment information.
# If approved, a 2nd transaction is run to cancel this transaction.
# If using TEST mode, odd dollar amounts will return
# an approval and even dollar amounts will return a decline.
account_id = "Merchant's Account ID Here"
secret_key = "Merchant's Secret Key Here"
mode = "TEST"
payment = BluePay(
account_id = account_id,
secret_key = secret_key,
mode = mode
name1 = "Bob",
name2 = "Tester",
addr1 = "123 Test St.",
addr2 = "Apt #500",
city = "Testville",
state = "IL",
zipcode = "54321",
country = "USA"
card_number = "4111111111111111",
card_expire = "1215",
cvv2 = "123"
payment.sale(amount = '3.00') # Sale Amount: $3.00
# Makes the API Request for processing the sale
# If transaction was approved..
payment_cancel = BluePay(
account_id = account_id, # Merchant's Account ID
secret_key = secret_key, # Merchant's Secret Key
mode = mode # Transaction Mode: TEST (can also be LIVE)
# Finds the previous payment by ID and attempts to void it
# Makes the API Request to void the payment
# Read response from BluePay
print 'Transaction Status: ' + payment_cancel.status_response
print 'Transaction Message: ' + payment_cancel.message_response
print 'Transaction ID: ' + payment_cancel.trans_id_response
print 'Transaction AVS Result: ' + payment_cancel.avs_code_response
print 'Transaction CVV2 Result: ' + payment_cancel.cvv2_code_response
print 'Masked Payment Account: ' + payment_cancel.masked_account_response
print 'Card Type: ' + payment_cancel.card_type_response
print 'Transaction Auth Code: ' + payment_cancel.auth_code_response