Coder Social home page Coder Social logo

sample-code-python's People

Contributors

abansalm avatar adavidw avatar agarwal-akshay avatar akankaria avatar anjali-nauhwar avatar ashtru avatar brianmc avatar chsriniv9 avatar dinsahu avatar gauravmokhasi avatar gnongsie avatar gnongsiej avatar karthikeyanrzp avatar khaaldrogo avatar namanbansal avatar saikatbasu01 avatar srmisra avatar sudhirkumar2018 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sample-code-python's Issues

Adding a Tip to a transaction

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()

Tests failing

Running the individual samples from the readme fails, with no response returned. This matches what I am seeing in my own transaction unit tests. This seems to coincide with the TLS 1.2 update to the Sandbox environment.

I am working on a Django 1.7.7 project, with Python 2.7.10 and OpenSSL 1.0.2l (latest). This all matches what I am seeing here: https://community.developer.authorize.net/t5/The-Authorize-Net-Developer-Blog/Request-for-Comments-API-Best-Practices/ba-p/53668?utm_campaign=Merchant%20TLS%20Notice.html&utm_medium=email&utm_source=Eloqua

Is this my environment, or the library code? Is there anything else I need to do re: the upgrade?
https://community.developer.authorize.net/t5/The-Authorize-Net-Developer-Blog/TLS-1-1-and-1-0-Disabled-in-Sandbox-on-April-30-2017-Updated/ba-p/57726

CVV and expiration date

This code accepts an invalid expiration date, even when I switch over to live mode.

This code does not show how to supply/validate the card holders name or the CVV. Is that possible?

Support payment nonce from accept.js

Is there a way to use this app with payment nonce (dataValueDescriptor) retrieved by accept.js? That seems like the most logic way instead of passing sensitive information like credit card from frontend to backend via network.

I am using accept.js to validate credit card information on the frontend, auth.net returns DataValueDescriptor which lets me use it to charge the card within 15 minutes. I pass the DataValueDescriptor on form submission to the backend (instead of CC information) and ready to charge the card. How do I do that?

Reference:
https://developer.authorize.net/api/reference/features/acceptjs.html#response-handling

get_transaction_details() method issue

ERROR 2023-03-23 06:38:22,279 authorizenet.sdk 154 execute Create Document Exception: <class 'pyxb.exceptions_.IncompleteElementContentError'>, (<authorizenet.apicontractsv1.CTD_ANON_70 object at 0x7f5927207f90>, <pyxb.utils.fac.Configuration object at 0x7f59272150d0>, None, None)

ImportError: No module named _vendor

I am working with the SDK for the first time and have installed the authorizenet module under Python 2.7.
My first attempt to run an example yields the traceback appended below. It's possible that I'm missing some other setup requirement, but my impression was that the examples should work right out of the box.

python PaymentTransactions/charge-credit-card.py

Traceback (most recent call last):
File "PaymentTransactions/charge-credit-card.py", line 5, in
from authorizenet.apicontrollers import *
File "/Users/gpetty/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/authorizenet/apicontrollers.py", line 9, in
from authorizenet import apicontrollersbase
File "/Users/gpetty/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/authorizenet/apicontrollersbase.py", line 9, in
from pip._vendor import requests
ImportError: No module named _vendor

Error when using Python 3.10

Error:

  File "~/Charge a Credit Card/python_charg_r01.py", line 13, in <module>
        from authorizenet import apicontractsv1
  File "~/.local/lib/python3.10/site-packages/authorizenet/apicontractsv1.py", line 9, in <module>
        import pyxb.binding
  File "~/.local/lib/python3.10/site-packages/pyxb/binding/__init__.py", line 8, in <module>
        from . import datatypes
  File "~/.local/lib/python3.10/site-packages/pyxb/binding/datatypes.py", line 1243, in <module>
        from . import content
  File "~/.local/lib/python3.10/site-packages/pyxb/binding/content.py", line 807, in <module>
        class _PluralBinding (collections.MutableSequence):
    AttributeError: module 'collections' has no attribute 'MutableSequence'

To fix this issue, you can modify the import in your code from:

import collections

to:

import collections.abc as collections

This change ensures compatibility with Python 3.10 and resolves the AttributeError you encountered.

in both files
content.py
basis.py

Python examples show failed transactions as successful

The examples show checking response.messages.resultCode=="Ok", however it's possible for a transaction to be reported as "Ok" but still not charged. Take this response I received for an Auth/Capture as an example:

2016-02-29 07:18:17,210 Received response: <?xml version="1.0" ?>
<createTransactionResponse xmlns="AnetApi/xml/v1/schema/AnetApiSchema.xsd" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <refId>NantucketSel-170</refId>
    <messages>
        <resultCode>Ok</resultCode>
        <message>
            <code>I00001</code>
            <text>Successful.</text>
        </message>
    </messages>
    <transactionResponse>
        <responseCode>2</responseCode>
        <authCode>XXXXXX</authCode>
        <avsResultCode>S</avsResultCode>
        <cvvResultCode/>
        <cavvResultCode/>
        <transId>XXXXXXXXXX</transId>
        <refTransID>XXXXXXXXXX</refTransID>
        <transHash>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</transHash>
        <testRequest>0</testRequest>
        <accountNumber>XXXX7095</accountNumber>
        <accountType>Visa</accountType>
        <errors>
            <error>
                <errorCode>27</errorCode>
                <errorText>The transaction has been declined because of an AVS mismatch. The address provided does not match billing address of cardholder.</errorText>
            </error>
        </errors>
    </transactionResponse>
</createTransactionResponse>

Please add examples that show how to detect all failed transactions.

Create a Customer Profile from a Transaction

Following this guide

Python 3.7.2

Returns the following error:
AttributeError: module 'authorizenet.apicontractsv1' has no attribute 'createCustomerProfileFromTransactionResponse'

As a very temporary fix I manually edited the apicontractsv1.py file and added the following lines:

createCustomerProfileFromTransactionResponse = pyxb.binding.basis.element(pyxb.namespace.ExpandedName(Namespace, 'createCustomerProfileFromTransactionResponse'), CTD_ANON_61, location=pyxb.utils.utility.Location('https://apitest.authorize.net/xml/v1/schema/AnetApiSchema.xsd', 3522, 2))

Namespace.addCategoryObject('elementBinding', createCustomerProfileFromTransactionResponse.name().localName(), createCustomerProfileFromTransactionResponse)

It's a very dirty hack, perhaps someone else can review and create a proper PR. Once this line was added, the expected response was received:

Successfully created a customer profile with id: XXXXXXX from transaction id: XXXXXXXXXX

Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}discountAmount at <unknown>[1:1142] to binding

Having just installed the Authorize.Net bindings for python 3.x, I get the following messages running the sample code:

Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}taxIsAfterDiscount at <unknown>[1:1176] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}taxRate at <unknown>[1:1516] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}taxAmount at <unknown>[1:1536] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}nationalTax at <unknown>[1:1560] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}localTax at <unknown>[1:1588] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}vatRate at <unknown>[1:1610] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}alternateTaxRate at <unknown>[1:1630] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}alternateTaxAmount at <unknown>[1:1668] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}totalAmount at <unknown>[1:1710] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}discountRate at <unknown>[1:1738] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}discountAmount at <unknown>[1:1768] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}taxIncludedInTotal at <unknown>[1:1802] to binding
Unable to convert DOM node {AnetApi/xml/v1/schema/AnetApiSchema.xsd}taxIsAfterDiscount at <unknown>[1:1848] to binding

Any ideas what's going on? Thanks!

transactionResponse cannot accept wildcard content

I have a payment profile all setup, and now I am trying to capture from it.

I am trying to follow the code here: https://github.com/AuthorizeNet/sample-code-python/blob/master/PaymentTransactions/charge-customer-profile.py

However, everytime that I run the code verbatim as in the above script, I encounter this issue:

StructuralBadDocumentError: {AnetApi/xml/v1/schema/AnetApiSchema.xsd}transactionResponse cannot accept wildcard content <pyxb.utils.saxdom.Element object at 0x7f8205dda850>

The full traceback:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/path/to/site-packages/authorizenet/apicontrollersbase.py", line 142, in execute
    self._response = apicontractsv1.CreateFromDocument(self._httpResponse)
  File "/path/to/site-packages/authorizenet/apicontractsv1.py", line 62, in CreateFromDocument
    saxer.parse(io.BytesIO(xmld))
  File "/usr/lib/python2.7/xml/sax/expatreader.py", line 110, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.7/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.7/xml/sax/expatreader.py", line 213, in feed
    self._parser.Parse(data, isFinal)
  File "/usr/lib/python2.7/xml/sax/expatreader.py", line 365, in end_element_ns
    self._cont_handler.endElementNS(pair, None)
  File "/path/to/site-packages/pyxb/binding/saxer.py", line 388, in endElementNS
    binding_object = this_state.endBindingElement()
  File "/path/to/site-packages/pyxb/binding/saxer.py", line 238, in endBindingElement
    _location=info.location)
  File "/path/to/site-packages/pyxb/binding/basis.py", line 2508, in append
    raise pyxb.StructuralBadDocumentError(container=self, content=value)
StructuralBadDocumentError: {AnetApi/xml/v1/schema/AnetApiSchema.xsd}transactionResponse cannot accept wildcard content <pyxb.utils.saxdom.Element object at 0x7f8205dda850>

Anyone else seen this?

The weird thing is that the transaction is captured when I login to Authorize.net.

No get-customer-payment-profile-list.py

Looks the the API reference expects a file, get-customer-payment-profile-list.py to be present in this repo, however this file is not present. This causes an error on the API reference site.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.