Transactions¶
Transaction objects contain data about payments. Every transaction object has
a transaction_id
and a price
.
You can create a basic credit card transaction by using
Transaction.create()
:
>>> import dinero
>>> transaction = dinero.Transaction.create(
price=200,
number='4111111111111111',
month='12',
year='2015',
)
>>> transaction.transaction_id
'0123456789'
This will charge the credit card $200. If you store the transaction_id
,
you can later retrieve the transaction object.
>>> transaction = dinero.Transaction.retrieve('0123456789')
>>> transaction.price
200
Note
Like many methods in dinero, Transaction.create()
and Transaction.retrieve()
accept a gateway_name
parameter. This parameter corresponds with the
gateway name that you created when configuring your gateways.
If you had the following configuration:
import dinero
dinero.configure({
'new-auth.net': {
'type': 'dinero.gateways.AuthorizeNet',
'default': True,
...
},
'old-auth.net': {
'type': 'dinero.gateways.AuthorizeNet',
...
},
})
If you don’t specify gateway_name
, it will use new-auth.net
. If
you wanted to use old-auth.net
, you could do something like the
following:
dinero.Transaction.create(
gateway_name='old-auth.net',
price=200,
...
)
When you have a transaction object, you can refund it:
transaction.refund()
If a transaction has not yet been settled, the transaction will simply be
voided, otherwise an actual refund will take place. If a transaction has
settled, you can pass refund the optional amount
argument, in case you only
want to give a partial refund.
transaction.refund(100)
Delayed Settlement¶
By default, dinero will automatically submit a transaction for settlement,
however you can override this by setting the settle
argument to False
.
When you need to settle a transaction, you can call
Transaction.settle()
:
transaction = dinero.Transaction.create(
price=200,
number='4111111111111111',
month='12',
year='2015',
settle=False,
)
...
transaction.settle()
If you need to cancel a transaction instead of settling it, just call
Transaction.refund()
.
API¶
-
class
dinero.
Transaction
(gateway_name, price, transaction_id, **kwargs)[source]¶ Transaction
is an abstraction over payments in a gateway. This is the interface for creating payments.-
classmethod
create
(price, **kwargs)[source]¶ Creates a payment. This method will actually charge your customer.
create()
can be called in several different ways.You can call this with the credit card information directly.
Transaction.create( price=200, number='4111111111111111', year='2015', month='12', # optional first_name='John', last_name='Smith,' zip='12345', address='123 Elm St', city='Denver', state='CO', cvv='900', email='johnsmith@example.com', )
If you have a
dinero.Customer
object, you can create a transaction against the customer.customer = Customer.create( ... ) Transaction.create( price=200, customer=customer, )
Other payment options include
card
andcheck
. Seedinero.CreditCard
for more information.
-
classmethod
retrieve
(transaction_id[, gateway_name=None])[source]¶ Fetches a transaction object from the gateway.
-
refund
([amount=None])[source]¶ If
amount
is None dinero will refund the full price of the transaction.Payment gateways often allow you to refund only a certain amount of money from a transaction. Refund abstracts the difference between refunding and voiding a payment so that normally you don’t need to worry about it. However, please note that you can only refund the entire amount of a transaction before it is settled.
-
classmethod