Package: getnet-python
getnet-pythonThis project is a fork ofGetnet-pyThis project provider a SDK to handler Getnet API.InstallationTo install getnet-py you can use pip:$ pip install getnet-pythonor pipenv:$ pipenv install getnet-pythonUsageFor use this library the following information is needed:Seller IDClient IDClient SecretThe following environments are supported:SandboxHomologProductionAt moment, we have support to the following services:TokenPaymentsCredit CardInstancing the clientfromgetnetimportEnvironment,Clientclient=Client("seller_id","client_id","client_secret",Environment.SANDBOX)client.auth()# Optional, will be executed if neededUsing the ServicesExamplesConsult Card BIN Informationscard_bin=client.card_bin("515590")# Card related information and StatusCustomercustomer_service=client.customer_service()Create Customercustomer_data=client.customer({"first_name":"Joao","last_name":"Pedro da Silva","document_type":"CPF","document_number":"77261241563","birth_date":"1988-04-08","phone_number":"5575999999999","celphone_number":"5575999999999","email":"fabvitor@test.com","observation":"Test CLient","customer_id":"77261241563",# or uuid4"seller_id":"6eb2412c-165a-41cd-b1d9-76c575d70a28","address":{"street":"Rua Test","number":"40","complement":"Casa","district":"Centro","city":"São Paulo","state":"SP","country":"Brasil","postal_code":"77019098",},})customer=customer_service.create(customer_data)Get Customercustomer=customer_service.get("77261241563")List All Customers Saved in Getnetcustomers=customer_service.all()Tokenizing a Credit Cardtoken=client.generate_card_token("5155901222280001",customer.customer_id)token.number_token# token genered in getnetVerify a Credit Cardcard_verified:bool=client.card_verified(number_token=tokenizado.number_token,expiration_month="12",expiration_year="28"cardholder_name="JOAO DA SILVA",brand="Mastercard",security_code="123",)# True or FalseGenerate a Credit Cardpayment_card=client.credit_card(number_token=tokenizado.number_token,cardholder_name="JOAO DA SILVA",security_code="123",brand="Mastercard",expiration_month="12",expiration_year="28")Generate a Orderpayment_order=client.order("12345")Generate a Payment Customerpayment_customer=client.customer(customer)Generate a Credit Card Paymentpayment=client.create_credit_transaction(amount="1000",delayed=False,pre_authorization=True,save_card_data=False,transaction_type="FULL",number_installments=1,order=payment_order,customer=payment_customer,card=payment_card,shipping_address={"street":"Rua Test","number":"40","city":"São Paulo","state":"SP","postal_code":"77019098"},# The user's address may be different from the address registered with the consumer)payment_id=payment.payment_id# IDstatus=payment.status# AUTHORIZEDAdjust a Payment Amountpayment_ajusted=client.adjust_credit_transaction(payment_id,"2000")payment_ajusted.status# APROVEDCapture a Credit Card Paymentcaptured_payment=client.capture_credit_transaction(payment_id,"2000")captured_payment.status# CONFIRMEDCancel a Credit Card Paymentcanceled_order=client.cancel_credit_transaction(payment_id)canceled_order.status# CANCELEDcancel_payment_credit.credit_cancel.message# "Credit transaction cancelled sucessfully"Handling error returnsErrors related to specific getnet returns can be accessed through the BusinessError ClassExample in Cancel Transaction:try:canceled_order=client.cancel_credit_transaction(payment_id)exceptExceptionasgetnet_error:error_code=getnet_error.details["error_code"]print(error_code)# PAYMENTS-082error_msg=getnet_error.details["description"]print(error_msg)# Cancelamento inválido