checkout / checkout-sdk-python Goto Github PK
View Code? Open in Web Editor NEWCheckout.com SDK for Python
Home Page: https://checkout.com
License: MIT License
Checkout.com SDK for Python
Home Page: https://checkout.com
License: MIT License
Is there any particular reason not to initialize the InstrumentsClient
with the Checkout API?
class CheckoutApi:
def __init__(self, **kwargs):
config = Config(**kwargs)
http_client = HTTPClient(config)
if(config.secret_key is not None):
self.payments = PaymentsClient(http_client)
if(config.public_key is not None):
self.tokens = TokensClient(http_client)
Would be nice to have something like:
from checkout_sdk.vaults import InstrumentsClient, TokensClient
class CheckoutApi:
def __init__(self, **kwargs):
...
if(config.public_key is not None):
self.instruments = InstrumentsClient(http_client)
This would simplify interacting with the instruments API.
A serializer can be useful, when the response fully or partially
CheckoutApiException does not hold the error_type returned in the API response. Example 422 response:
{
"request_id": "2a16b1e2-18f1-9099-a4e7-db66871be2b9",
"error_type": "request_invalid",
"error_codes": [
"processing_channel_id_required"
]
}
The documentation in the README.md
has some useful, specific examples about how to request a payment. However, having tried to request a payment using the Source Type: token
example it appears that the documentation does not match the code.
The example given is:
payment = api.payments.request(
source={
'token': 'tok_...'.
'billing_address': { ... },
'phone': { ... }
},
amount=100, # cents
currency=sdk.Currency.USD, # or 'usd'
reference='pay_ref'
)
print(payment.id)
However, this gives a ValueError
because the underlying code cannot determine the request type - ValueError: Payment source missing. Please specify a valid card or token.
.
Having looked through the code I determined that the token
field should be a top level item, alongside source
. This fixed the immediate problem, but then raised another in that validation was expecting a customer
attribute as well, which contained either the email address, or customer ID. This is also undocumented.
The current errors class doesn't cater for API and Business validation declines responses such as:
"errorMessageCodes": [
"70034"
],
"errors": [
"Invalid card id"
]
Hello team,
When I've tried payment request by Source Id without CVV on staging/Sandbox environment it's working fine, when I'm trying on the Production environment by Source Id without CVV it's not working and throwing this error "ERROR / INVALID REQUEST PARAMETERS" code "20006", But when I m trying with CVV on Production then it's working fine.
Can somebody confirm, Is CVV is mandatory? or optional
https://github.com/checkout/checkout-sdk-python#source-type-id
{
"source": {
"id":"src_xxxx"
},
"amount": 100,
"currency": "PKR",
"reference": "xx-xx-xxx"
}
Importing checkout_sdk
results in an error with version 3.0.19.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/checkout/lib/python3.11/site-packages/checkout_sdk/__init__.py", line 3, in <module>
from checkout_sdk.checkout_sdk import CheckoutSdk # noqa
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/tmp/checkout/lib/python3.11/site-packages/checkout_sdk/checkout_sdk.py", line 3, in <module>
from checkout_sdk.default_sdk import DefaultSdk
File "/tmp/checkout/lib/python3.11/site-packages/checkout_sdk/default_sdk.py", line 5, in <module>
from checkout_sdk.checkout_api import CheckoutApi
File "/tmp/checkout/lib/python3.11/site-packages/checkout_sdk/checkout_api.py", line 15, in <module>
from checkout_sdk.payments.sessions.sessions_client import PaymentSessionsClient
ModuleNotFoundError: No module named 'checkout_sdk.payments.sessions'
$ pip install checkout-sdk==3.0.19
$ python -c 'import checkout_sdk'
Probably introduced by #148.
I think that a __init__.py
file is missing in checkout_sdk/payments/sessions
.
While using test master card numbers, I'm getting error with status 422
my code:
def request_donation_payment(data):
token = data.get('token')
amount = data.get('donation_amount')
payment_reference = 'enwwf-donation'
payment_description = 'Emirates Nature - WWF Donation Payment'
phone_number = data.get('phone')
first_name = data.get('first_name')
last_name = data.get('last_name')
email = data.get('email')
customer_name = first_name+' '+last_name
language = data.get('language')
# API Keys
api = CheckoutSdk.builder() \
.secret_key(SECRET_KEY) \
.public_key(PUBLIC_KEY) \
.environment(ENVIRONMENT) \
.build()
phone = Phone()
phone.number = phone_number
request_token_source = PaymentRequestTokenSource()
request_token_source.token = token
customer_request = CustomerRequest()
customer_request.email = email
customer_request.name = customer_name
payment_individual_sender = PaymentInstrumentSender()
three_ds_request = ThreeDsRequest()
three_ds_request.enabled = True
request = PaymentRequest()
request.source = request_token_source
request.capture = False
request.reference = payment_reference
request.description = payment_description
request.amount = amount*100
request.currency = Currency.AED
request.customer = customer_request
request.sender = payment_individual_sender
request.processing_channel_id = settings.CKO_PROCESSING_CHANNEL_ID
request.three_ds = three_ds_request
if language == 'ar':
request.success_url = settings.DONATION_APP_URL+'/ar/loading'
request.failure_url = settings.DONATION_APP_URL+'/ar/loading'
else:
request.success_url = settings.DONATION_APP_URL+'/loading'
request.failure_url = settings.DONATION_APP_URL+'/loading'
logger = logging.getLogger(__name__)
try:
response = api.payments.request_payment(request)
payment_request_data = {
'amount': amount,
'status_code': response.http_metadata.status_code,
'reference': response.reference,
}
logger.info(json.dumps(["PAYMENT_LOG", payment_request_data]))
return response
except CheckoutApiException as err:
logger.error("Donation Payment Error")
error_details = err.error_details
http_status_code = err.http_metadata.status_code if err.http_metadata else None
logger.error('ERROR CODE: %s', http_status_code)
logger.error('ERROR LIST: %s', json.dumps(error_details))
return err
response comes as attachment.
When playing around with the sdk I'm getting AuthenticationError('Your API key is invalid.')
.
I got the secret key from the checkout.com sandbox page
And I can't seem to find the root cause of this.
Please send help
This is to be able to implement alternative payments
The CheckoutApiException
has incorrectly defined types
The CheckoutApiException is defined as having error_details
as a dict
when we can see in the __init__
method that self.error_details
can be set to None
. Thus error_details
is actually Optional[dict]
.
However, in some cases error_details
may not be set when response.text
is null
or missing. An example of such case is when the API responds with a 403
on a payout, error_details
is not an available attribute on this exception. Which also means the python examples in the documentation isn't complete for this case and raises an AttributeError on 403.
Lastly error_details
should actually be a list
instead of a dict
according to the API documentation, as you can see in the image provided the API mentions that error_codes
is an array
A final point, it would be worthwhile introducing some clear data structures to this library as most of the structs have to be guessed by reading the attributes in the tests. This would be far more helpful than trying to figure out the struct from a nested ResponseWrapper object.
Hi,
I just started implementing updated SDK version and i wonder why none of requests related classes (for example: PaymentRequest, RefundRequest) or related objects (for example: CustomerRequest, ThreeDsRequest) has no init methods? Is it conceptional or you don't mind if i add it?
Btw who i should contact to contribute? :)
Regards,
Michael
Where to get this keys? Which steps i should go to find them? Cant found them at all
For Default account systems: CHECKOUT_PUBLIC_KEY & CHECKOUT_SECRET_KEY
For Four account systems: CHECKOUT_FOUR_PUBLIC_KEY & CHECKOUT_FOUR_SECRET_KEY
For Four account systems (OAuth): CHECKOUT_FOUR_OAUTH_CLIENT_ID & CHECKOUT_FOUR_OAUTH_CLIENT_SECRET
These raised exceptions do not have amessage
attribute. Thus the log message in the readme fails with AttributeError
.
Also the exception definition doesn't contain an error_code
attribute
except sdk.errors.CheckoutSdkError as e:
print('{0.http_status} {0.error_code} {0.elapsed} {0.event_id} // {0.message}'.format(e))
https://github.com/checkout/checkout-sdk-python#payment-request-example-with-n3d-downgrade-option
Also 'error_codes'
seems like a valuable attribute to have on the error logging e.g: ['customer_id_invalid', 'destination_token_invalid']
When giving bad card data on purpose while doing a payment request, the exception from CheckoutSdkError
is missing values forcing me to run the exception handling this way:
except checkout.errors.CheckoutSdkError as e:
status_code = e.http_status if e.http_status is not None else 500
abort(status_code, e.message, error_code=e.error_code)
Please add device_session_id field in risk (RiskRequest) as needed for Risk.js integration
https://www.checkout.com/docs/business-operations/prevent-fraud/integrate-with-risk-js
add device_session_id field to RiskRequest class:
class RiskRequest:
enabled: bool
device_session_id: str
When trying to simulate 3D Secure payment requests, the response object is breaking with the below error:
File "/.../checkout_sdk/payments/payment_processed.py", line 8, in init
self._card = Card(api_response.body['card'])
KeyError: 'card'
How to get?
Do you accept contributions to this repo?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.