Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
Feature/installment plan (#102)
Browse files Browse the repository at this point in the history
* Primeiro teste feito

* A IDE estava reclamando do stub, chega me assustou

* fmt

* Corrige campos

* Corrige testes

* Começa exemplo, mas o import esta reclamando

* Adiciona imports necessários

* Corrige InstallmentPlan

* Cria testes para novos métodos

* Adiciona exemplos e os respectivos .json com as remoções marketplace_id

* Adiciona W503 no ignore do .flake8

* fmt

* Corrige BDD

Co-authored-by: Rodrigo Castro <rodrigondec@gmail.com>

* Corrige stub

Co-authored-by: Rodrigo Castro <rodrigondec@gmail.com>

* Melhora _validate_number_installments e testes

* Corrige stubs

* Corrige testes e lógicas

* fmt

* Corrige argumentos dos stubs

* Corrige stub again :|

Co-authored-by: Rodrigo Castro <rodrigondec@gmail.com>
  • Loading branch information
PedroRegisPOAR and rodrigondec committed Sep 4, 2020
1 parent c998ef6 commit 86c1999
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[flake8]
ignore = D203
ignore = D203, W503
exclude =
.git,
venv,
Expand Down
150 changes: 150 additions & 0 deletions examples/data/add_transaction_card_not_present_installment_plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"id": "bb88b8cc9c944a419b854b5548a279e7",
"resource": "transaction",
"status": "succeeded",
"amount": "543.21",
"original_amount": "543.21",
"currency": "BRL",
"description": "Uma descri\u00e7\u00e3o breve da motiva\u00e7\u00e3o da sua transa\u00e7\u00e3o",
"payment_type": "credit",
"transaction_number": "Z133937-000260004",
"gateway_authorizer": "cielo",
"app_transaction_uid": null,
"refunds": null,
"rewards": null,
"discounts": null,
"pre_authorization": null,
"sales_receipt": "f9a0816e5f9e490eae89c689842785c9",
"on_behalf_of": "25037b2978b14e7fa5b902d9322e8426",
"customer": "0b05a360f4b749498f74e13004c08024",
"statement_descriptor": "LOJA DO JOAO",
"payment_method": {
"id": "6408de3a490b4679adfc462810b68a85",
"resource": "card",
"description": null,
"card_brand": "MasterCard",
"first4_digits": "3021",
"last4_digits": "2922",
"expiration_month": "5",
"expiration_year": "2030",
"holder_name": "foo",
"is_active": true,
"is_valid": true,
"is_verified": false,
"customer": "0b05a360f4b749498f74e13004c08024",
"fingerprint": "a759ce86626c7dd4805409d0384c4cfb3097ee30ab1f631ecf99fb30291ec99e",
"address": null,
"verification_checklist": {
"postal_code_check": "unchecked",
"security_code_check": "fail",
"address_line1_check": "unchecked"
},
"metadata": {},
"uri": "/v1/marketplaces/foo/cards/6408de3a490b4679adfc462810b68a85",
"created_at": "2020-06-08T20:51:58+00:00",
"updated_at": "2020-06-08T20:52:00+00:00"
},
"source": {
"id": "ff0f409b1040464da0dd94f562f263ff",
"status": "used",
"usage": "single_use",
"amount": "543.21",
"currency": "BRL",
"description": null,
"statement_descriptor": null,
"type": "card",
"card": {
"id": "6408de3a490b4679adfc462810b68a85",
"resource": "card",
"description": null,
"card_brand": "MasterCard",
"first4_digits": "3021",
"last4_digits": "2922",
"expiration_month": "5",
"expiration_year": "2030",
"holder_name": "foo",
"is_active": true,
"is_valid": true,
"is_verified": false,
"customer": "0b05a360f4b749498f74e13004c08024",
"fingerprint": "a759ce86626c7dd4805409d0384c4cfb3097ee30ab1f631ecf99fb30291ec99e",
"address": null,
"verification_checklist": {
"postal_code_check": "unchecked",
"security_code_check": "fail",
"address_line1_check": "unchecked"
},
"metadata": {},
"uri": "/v1/marketplaces/foo/cards/6408de3a490b4679adfc462810b68a85",
"created_at": "2020-06-08T20:51:58+00:00",
"updated_at": "2020-06-08T20:52:00+00:00",
"amount": "543.21"
}
},
"point_of_sale": {
"entry_mode": "manually_keyed",
"identification_number": null
},
"installment_plan": {
"number_installments": "12",
"mode": "interest_free"
},
"refunded": false,
"voided": false,
"captured": true,
"fees": "21.67",
"fee_details": [
{
"amount": "21.67",
"prepaid": false,
"currency": "BRL",
"type": "zoop_fee_brazil",
"is_gateway_fee": false,
"description": "Zoop card-present transaction fee"
}
],
"location_latitude": null,
"location_longitude": null,
"uri": "/v1/marketplaces/foo/transactions/bb88b8cc9c944a419b854b5548a279e7",
"metadata": {},
"expected_on": "2020-10-05T00:00:00+00:00",
"created_at": "2020-09-04T18:15:02+00:00",
"updated_at": "2020-09-04T18:15:05+00:00",
"payment_authorization": {
"authorizer_id": "000260004",
"authorization_code": "133937",
"authorization_nsu": "20180510122911535"
},
"history": [
{
"id": "e11fed0d9a9d44b2a43341d78030c118",
"transaction": "bb88b8cc9c944a419b854b5548a279e7",
"amount": "543.21",
"operation_type": "created",
"status": "succeeded",
"response_code": null,
"response_message": null,
"authorization_code": null,
"authorizer_id": null,
"authorization_nsu": null,
"gatewayResponseTime": null,
"authorizer": null,
"created_at": "2020-09-04 18:15:02"
},
{
"id": "ed4d87c92699484da7eaa1192dd7c9c0",
"transaction": "bb88b8cc9c944a419b854b5548a279e7",
"amount": "543.21",
"operation_type": "authorization",
"status": "succeeded",
"response_code": "00",
"response_message": "",
"authorization_code": "133937",
"authorizer_id": "000260004",
"authorization_nsu": "20180510122911535",
"gatewayResponseTime": "2210",
"authorizer": "cielo",
"created_at": "2020-09-04 18:15:04"
}
]
}
150 changes: 150 additions & 0 deletions examples/data/add_transaction_card_present_installment_plan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
{
"id": "88c1c5b0c30a46e0b2b0efa3f99554f4",
"resource": "transaction",
"status": "succeeded",
"amount": "543.21",
"original_amount": "543.21",
"currency": "BRL",
"description": "Uma descri\u00e7\u00e3o breve da motiva\u00e7\u00e3o da sua transa\u00e7\u00e3o",
"payment_type": "credit",
"transaction_number": "Z133937-000260004",
"gateway_authorizer": "cielo",
"app_transaction_uid": null,
"refunds": null,
"rewards": null,
"discounts": null,
"pre_authorization": null,
"sales_receipt": "9b04c4b829f44fe79eefc3e2feb8e29b",
"on_behalf_of": "25037b2978b14e7fa5b902d9322e8426",
"customer": null,
"statement_descriptor": "KIMBERLY STEVENSON",
"payment_method": {
"id": "80a63e4e413141148f387a60089d680e",
"resource": "card",
"description": null,
"card_brand": "Visa",
"first4_digits": "4497",
"last4_digits": "2521",
"expiration_month": "5",
"expiration_year": "2030",
"holder_name": "foo",
"is_active": false,
"is_valid": true,
"is_verified": false,
"customer": null,
"fingerprint": "f21a1ee8457c9c8b995d18e597f457c6bd523cfef716a02ddd7693094cdaff5f",
"address": null,
"verification_checklist": {
"postal_code_check": "unchecked",
"security_code_check": "unchecked",
"address_line1_check": "unchecked"
},
"metadata": {},
"uri": "/v1/marketplaces/foo/transactions/80a63e4e413141148f387a60089d680e",
"created_at": "2020-09-04T18:28:05+00:00",
"updated_at": "2020-09-04T18:28:08+00:00"
},
"source": {
"id": "8d396cb7df464f3697572286d28df726",
"status": "used",
"usage": "single_use",
"amount": "543.21",
"currency": "BRL",
"description": null,
"statement_descriptor": null,
"type": "card",
"card": {
"id": "80a63e4e413141148f387a60089d680e",
"resource": "card",
"description": null,
"card_brand": "Visa",
"first4_digits": "4497",
"last4_digits": "2521",
"expiration_month": "5",
"expiration_year": "2030",
"holder_name": "foo",
"is_active": false,
"is_valid": true,
"is_verified": false,
"customer": null,
"fingerprint": "f21a1ee8457c9c8b995d18e597f457c6bd523cfef716a02ddd7693094cdaff5f",
"address": null,
"verification_checklist": {
"postal_code_check": "unchecked",
"security_code_check": "unchecked",
"address_line1_check": "unchecked"
},
"metadata": {},
"uri": "/v1/marketplaces/foo/transactions/80a63e4e413141148f387a60089d680e",
"created_at": "2020-09-04T18:28:05+00:00",
"updated_at": "2020-09-04T18:28:08+00:00",
"amount": "543.21"
}
},
"point_of_sale": {
"entry_mode": "manually_keyed",
"identification_number": null
},
"installment_plan": {
"number_installments": "11",
"mode": "interest_free"
},
"refunded": false,
"voided": false,
"captured": true,
"fees": "21.67",
"fee_details": [
{
"amount": "21.67",
"prepaid": false,
"currency": "BRL",
"type": "zoop_fee_brazil",
"is_gateway_fee": false,
"description": "Zoop card-present transaction fee"
}
],
"location_latitude": null,
"location_longitude": null,
"uri": "/v1/marketplaces/foo/transactions/88c1c5b0c30a46e0b2b0efa3f99554f4",
"metadata": {},
"expected_on": "2020-10-05T00:00:00+00:00",
"created_at": "2020-09-04T18:28:05+00:00",
"updated_at": "2020-09-04T18:28:10+00:00",
"payment_authorization": {
"authorizer_id": "000260004",
"authorization_code": "133937",
"authorization_nsu": "20180510122911535"
},
"history": [
{
"id": "50a0f6376cd2478e84bf20965af7fcb9",
"transaction": "88c1c5b0c30a46e0b2b0efa3f99554f4",
"amount": "543.21",
"operation_type": "created",
"status": "succeeded",
"response_code": null,
"response_message": null,
"authorization_code": null,
"authorizer_id": null,
"authorization_nsu": null,
"gatewayResponseTime": null,
"authorizer": null,
"created_at": "2020-09-04 18:28:08"
},
{
"id": "420e68fb065f4c41a2ef1e3766d88707",
"transaction": "88c1c5b0c30a46e0b2b0efa3f99554f4",
"amount": "543.21",
"operation_type": "authorization",
"status": "succeeded",
"response_code": "00",
"response_message": "",
"authorization_code": "133937",
"authorizer_id": "000260004",
"authorization_nsu": "20180510122911535",
"gatewayResponseTime": "2204",
"authorizer": "cielo",
"created_at": "2020-09-04 18:28:10"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from zoop_wrapper import ZoopWrapper, Transaction, Source, Token
from zoop_wrapper import ZoopWrapper, Transaction, Source, Token, InstallmentPlan
from examples.utils import dump_response

"""
Expand Down Expand Up @@ -34,6 +34,10 @@
usage="single_use",
amount=quantia_em_centavos,
),
installment_plan=InstallmentPlan(
number_installments=12,
mode="interest_free",
),
)

response = client.add_transaction(t)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import os

from factory.faker import Faker

from zoop_wrapper import ZoopWrapper, Transaction, Source, Token, InstallmentPlan
from examples.utils import dump_response

"""
Nesse momento as constantes podem ser criadas no arquivo .py.
Mas é recomendado utilizar como variável de ambiente em um '.env'
"""
from zoop_wrapper.constants import MARKETPLACE_ID, ZOOP_KEY


client = ZoopWrapper(marketplace_id=MARKETPLACE_ID, key=ZOOP_KEY)

seller_brian = "0b05a360f4b749498f74e13004c08024"
seller_denise = "25037b2978b14e7fa5b902d9322e8426"

# Essa flag indica se a transação deve ser apenas pré autorizada ou capturada
capture_flag = True

# Equivalente à R$543,21
quantia_em_centavos = "54321"

t = Transaction(
customer=seller_brian,
description="Uma descrição breve da motivação da sua transação",
on_behalf_of=seller_denise,
payment_type="credit",
capture=capture_flag,
source=Source(
amount=quantia_em_centavos,
card=Token(
card_number=Faker("credit_card_number").generate(),
expiration_month="05",
expiration_year="2030",
holder_name="foo",
security_code=123,
),
usage="single_use",
),
installment_plan=InstallmentPlan(
number_installments=11,
mode="interest_free",
),
)


response = client.add_transaction(t)

dump_response(response, os.path.basename(__file__).split(".")[0])
4 changes: 3 additions & 1 deletion tests/models/test_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def test_init_custom_fields_card(self):
We set the CARD_IDENTIFIER to 'foo'
and pass foo='bar' on args!
"""
instance = MagicMock(CARD_IDENTIFIER="foo",)
instance = MagicMock(
CARD_IDENTIFIER="foo",
)

Token.init_custom_fields(instance, foo="bar")
self.assertEqual(instance.token_type, instance.CARD_TYPE)
Expand Down

0 comments on commit 86c1999

Please sign in to comment.