sample-code-python icon indicating copy to clipboard operation
sample-code-python copied to clipboard

Adding a Tip to a transaction

Open sampocs opened this issue 6 years ago • 1 comments

In the documentation, it shows that there is a Tip field of type Decimal that can be included in a transaction (https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card).

I have been unable to include this field in my code when using the python SDK. It runs successfully if I get rid of the following lines:

tip = apicontractsv1.extendedAmountType()
tip.amount = Decimal('2.00')
...
transactionrequest.tip = tip 

However, when I try to include a tip, I receive the error message is: "The Tip amount is invalid." How should I format this field?

I've included all my code for reference but the 3 lines above should really be the only lines of any importance.

Thanks!

Code:

merchantAuth = apicontractsv1.merchantAuthenticationType()
merchantAuth.name = API_LOGIN_ID
merchantAuth.transactionKey = TRANSACTION_KEY

profileToCharge = apicontractsv1.customerProfilePaymentType()
profileToCharge.customerProfileId = 'XXX'
profileToCharge.paymentProfile = apicontractsv1.paymentProfile()
profileToCharge.paymentProfile.paymentProfileId = 'XXX'

customer = apicontractsv1.customerDataType()
customer.id = 'XXX'

line_items = apicontractsv1.ArrayOfLineItem()

line_item = apicontractsv1.lineItemType()
line_item.itemId = 'XXX'
line_item.name = 'XXX'
line_item.quantity = 'XXX'
line_item.unitPrice = 'XXX'
line_items.lineItem.append(line_item)

order_type = apicontractsv1.orderType()
order_type.description = 'XXX'

tip = apicontractsv1.extendedAmountType()
tip.amount = Decimal('2.00')

tax = apicontractsv1.extendedAmountType()
tax.amount = 'XXX'

transactionrequest = apicontractsv1.transactionRequestType()
transactionrequest.transactionType = 'authOnlyTransaction'
transactionrequest.amount = 'XXX'
transactionrequest.profile = profileToCharge
transactionrequest.customer = customer
transactionrequest.lineItems = line_items
transactionrequest.order = order_type
transactionrequest.tip = tip
transactionrequest.tax = tax

createtransactionrequest = apicontractsv1.createTransactionRequest()
createtransactionrequest.merchantAuthentication = merchantAuth
createtransactionrequest.transactionRequest = transactionrequest
createtransactionrequest.refId = 'XXX'

createtransactioncontroller = createTransactionController(createtransactionrequest)
createtransactioncontroller.execute()

auth_response = createtransactioncontroller.getresponse()

sampocs avatar Mar 07 '19 09:03 sampocs

Added these code imported the library :_ from decimal import Decimal Below code give the output after adding tip to the code

from decimal import Decimal tip = apicontractsv1.extendedAmountType() tip.amount = Decimal('2.00') transactionrequest.tip = tip

PRERNA1829 avatar Sep 30 '24 15:09 PRERNA1829