Package: etpay-sdk
ETpay Python SDKOfficial ETpay SDK for PythonInstallationUsingpypipipinstalletpay_sdkTesting with whl filepipinstallpath/to/whlfile/etpay_sdk-1.0.1-py3-none-any.whlHow to useConfigure ETpay module:Method:ETpay.Configs(args: ConfigsArgs)Parameters:ConfigsArgsParameterTypeRequiredDescriptionmerchant_codestringfalseMerchant code of the clientmerchant_api_tokenstringfalseMerchant api token of the clientapi_urlstringfalseApi url of the clientExample code# Import ETpay moduleimportetpay_sdkasEtpay# Declare global vars# Commerce identifier provided by ETpay.MERCHANT_CODE="valid_code"# Secret token used to authenticate against the API provided by ETpay.MERCHANT_API_TOKEN="valid_api_key"# Api url provided by ETpay.API_URL="valid_api_url"# Configure moduleconfigs=Etpay.Configs(MERCHANT_CODE,MERCHANT_API_TOKEN,API_URL)Metadata ETpay module:Method:ETpay.Metadata(args: [MetadataParams])Parameters:MetadataParamsParameterTypeRequiredDescriptionnamestringtrueJSON key called "name"valuestringtrueJSON key called "value"showbooleantrueJSON key called "show"Example code# Import ETpay moduleimportetpay_sdkasEtpay# Creation of Metadata Objectmetadata=Etpay.Metadata([{"name":"NAME","value":"VALUE","show":True},])TransactionParams ETpay module:Method:ETpay.TransactionParams(args: CreateTransactionArgs)Parameters:CreateTransactionArgsParameterTypeRequiredDescriptionmerchant_order_idstringtrueId used by the merchant to identify the transaction.order_amountstringtrueTransaction amount.customer_emailstringfalseCustomer email.payment_completed_urlstringtrueURL to which the API will redirect in the event of a successful payment.payment_cancellation_urlstringtrueURL to which the API will redirect in the event that the payer explicitly cancels the payment, or an unforeseen error occurs.user_bank_codestringfalseIf this field is sent, the session starts with the bank already selected.user_rutstringfalseIf this field is sent, the session starts with the client's RUT already entered in the respective field.is_rut_blockstringfalseIf this field is sent, the session starts with the client's RUT field already blocked. Important to consider sendinguser_ruttogether wit this attribute.concatstringfalseWhen merchants have URLs that vary based on different inputs, this value is what ETpay uses to recognize the character/symbol that concatenates those inputs.metadataMetadatafalseData showing on transaction processExample code# Import ETpay moduleimportetpay_sdkasEtpay# Obligatory ParamsMERCHANT_ORDER_ID="{ORDER_ID}"ORDER_AMOUNT=500PAYMENT_COMPLETED_URL="{URL_SUCCESS}"PAYMENT_CANCELLATION_URL="{URL_CANCEL}"# Optional ParamsCUSTOMER_EMAIL="email@email.com"USER_BANK_CODE="USER_BANK_CODE"USER_RUT="USER_RUT"IS_RUT_BLOCK="IS_RUT_BLOCK"CONCAT="{“&”}"METADATA=Etpay.Metadata([{"name":"NAME","value":"VALUE","show":True},])# TransactionParams moduleTransactionParams=Etpay.TransactionParams(MERCHANT_ORDER_ID,ORDER_AMOUNT,CUSTOMER_EMAIL,PAYMENT_COMPLETED_URL,PAYMENT_CANCELLATION_URL,USER_BANK_CODE,USER_RUT,IS_RUT_BLOCK,CONCAT,METADATA)Create transaction Object:Method:ETpay.Transaction.create()Retrieve transaction status:Method:ETpay.Transaction.status(args: TransactionStatusArgs)Parameters:TransactionStatusArgsParameterTypeRequiredDescriptionsession_tokenstringfalseReceived when transaction was createdmerchant_order_idstringfalseInternal merchant order identifierpayment_tokenstringfalseReceived when transaction was createdValidate a transaction result:Method:ETpay.Transaction.verify(token: string, signature_token: string)Parameters:ParameterTypeRequiredDescriptiontokenstringtrueReceived token on transaction succeedsignature_tokenstringtrueSignature Received when transaction was createdExample code#Definition of client datamerchantcode="MERCHANT_CODE"merchantapitoken="MERCHANT_API_TOKEN"apiurl="API_URL"# Creation of Metadata Object. Usefull in TransactionParams Object to create JSON for '/session/initialize' consultmetadata=Etpay.Metadata([{"name":"NAME","value":"VALUE","show":True},])# Creation of TransactionParams. Work for containt the parameters for '/session/initialize' JSONtransaction_param=Etpay.TransactionParams(order_amount=1,merchant_order_id="merchant_order_id",customer_email="example@example.com",payment_completed_url="https://www.google.com",payment_cancellation_url="https://www.google.com",metadata=metadata)# Creation of Configs. Contain configurations parameters of Clientconfigure=Etpay.Configs(merchantcode,merchantapitoken,apiurl)# Creation of Transactions Object. Contain configurations and parameters for consult methodstransaction=Etpay.Transactions(configure,transaction_param)# Method to make de '/merchant/check_payment_status' consult and obtain the correct JSONcreate_response=transaction.create()print(create_response.json())# Method to make de '/session/initialize' consult and obtain the correct JSONstatus_response=transaction.status(merchant_order_id="MERCHANT_ORDER_ID")print(status_response.json())# Method to verify a JWT using the signature token as a keyjwt_decode=transaction.verify("eyJh[...]dHxE","ZPfh[...]GqPl")print(jwt_decode)Response Object to "create"{"token":"LnA0o[...]UaDgTa","signature_token":"J1Bdd[...]jzsLD5",// terms_url can be null when module is configured with ETpay MX api"terms_url":"https://<etpay-terms-url>"}Response Object to "status"{"session_token":"wWkob[...]wC0L5","merchant_account_bank":"cl_estado","merchant_account_type":"cuenta_vista","merchant_account":"19687526","merchant_name":"Sandbox Developer Merchant","merchant_currency":"CLP","merchant_order_id":"oc1234566","merchant_amount":1,"user_bank":"Banco de prueba","user_rut":"111111111","user_account":"Cuenta Corriente 12345678","payment_token":"prNZK[...]yuPfd","payment_status":true,"payment_process":"auto","iat":1643663332}Response Object to "verify"[{"session_token":"wWkob[...]wC0L5","merchant_account_bank":"cl_estado","merchant_account_type":"cuenta_vista","merchant_account":"19687526","merchant_name":"Sandbox Developer Merchant","merchant_currency":"CLP","merchant_order_id":"oc1234566","merchant_amount":1,"user_bank":"Banco de prueba","user_rut":"111111111","user_account":"Cuenta Corriente 12345678","payment_token":"prNZK[...]yuPfd","payment_status":true,"payment_process":"auto","iat":1643663332}]Error HandlerEtpay errorIn the very unlikely case of a system error, with a disconnection with the ETpay backend, a redirect to the failure URL will be made, with a JWT signed with the session_token (instead of the signature_token).{"session_token":"08Zyd[...]Abv9Z","system_error":true,"iat":1564667797}SDK common errors TransactionErrorCommon CauseTypeError: Type use in 'configure' is incorrectConfigure argument recive it's not Config ObjectTypeError: Type use in 'transaction_params' is incorrectTransaction_params argument recive it's not TransactionParams ObjectSDK common errors Transaction.status()ErrorCommon CauseValueError: The function requires at least one argumentNo argument sent in this method. Is required at least oneSDK common errors Transaction.verify()ErrorCommon Causejwt.exceptions.DecodeError: Invalid header paddingHeader of JWT is incompletejwt.exceptions.InvalidSignatureError: Signature verification failedThe JWT is incomplete. The token is incompleteInvalid header string: 'utf-8' codec can't decode byte 0x88 in position 6: invalid start byteFirst section of JWT is incompleteTypeError: Type use in 'token' is incorrectToken argument recive it's not StringTypeError: Type use in 'signature_token' is incorrectsignature_token argument recive it's not StringSDK common errorsErrorCommon Causerequests.exceptions.ConnectionError: HTTPSConnectionPool(host='api-sandbox.etpaymen', port=443): Max retries exceeded with url: /session/initialize (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000002A296CC3348>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))URL used is invalid. Fail to establish connection