Return Funds to a Customer

This code steps you through the process of refunding payments that have been made on settled transactions.

There are three outcomes when processing credit card transactions:

  1. Approved
  2. Declined
  3. Error

Refunds can only be run on 'Approved' transactions that have been settled. 'Declined' transactions cannot be refunded. As a result, in order to test the refund process, you must first pass an odd dollar amount. This will return the transaction with an 'Approved' status. Then, you can test a refund for the transaction.

An error could result from a variety of conditions such as missing data, invalid card numbers, and expiration dates provided in invalid formats.

The following sample code calls a routine from our Code Library.

# 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 partially refund the
# customer for $1.75 of the $3.00.
# 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"
) = '3.00') # Sale Amount: $3.00

# Makes the API Request for processing the sale

# If transaction was approved..
if payment.is_successful_response():

    payment_return = 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)

    # Creates a refund transaction against previous sale
        transaction_id = payment.trans_id_response, # id of the transaction to refund
        amount = '1.75' # partial refund of $1.75

    # Makes the API Request for processing the sale

    # Read response from BluePay
    print 'Transaction Status: ' + payment_return.status_response
    print 'Transaction Message: ' + payment_return.message_response
    print 'Transaction ID: ' + payment_return.trans_id_response
    print 'AVS Response: ' + payment_return.avs_code_response
    print 'CVV2 Response: ' + payment_return.cvv2_code_response
    print 'Masked Payment Account: ' + payment_return.masked_account_response
    print 'Card Type: ' + payment_return.card_type_response
    print 'Auth Code: ' + payment_return.auth_code_response
    print payment_return.message_response
BluePay Processing, LLC is a registered ISO of Wells Fargo Bank, N.A., Walnut Creek, CA, U.S.A.
BluePay Canada ULC, is a Registered ISO/MSP of Peoples Trust Company, Vancouver, Canada.