Skip to content

Commit

Permalink
Merge pull request #86 from TransbankDevelopers/chore/deferred-captur…
Browse files Browse the repository at this point in the history
…e-fulltransaction

Support deferred capture method on FullTransaction
  • Loading branch information
isabellaahc authored May 27, 2021
2 parents 09d705f + a8c1fd2 commit d7fea5a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 7 deletions.
7 changes: 7 additions & 0 deletions transbank/transaccion_completa/request/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ def __init__(self, amount: float):
self.amount = amount


class TransactionCaptureRequest(object):
def __init__(self, buy_order: str, authorization_code: str, capture_amount: float):
self.buy_order = buy_order
self.authorization_code = authorization_code
self.capture_amount = capture_amount


class TransactionInstallmentsRequest(object):
def __init__(self, installments_number: float):
self.installments_number = installments_number
19 changes: 19 additions & 0 deletions transbank/transaccion_completa/response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __repr__(self):
self.accounting_date, self.transaction_date, self.authorization_code, self.payment_type_code,
self.response_code, self.installments_number, self.installments_amount, self.balance)


class TransactionStatusResponse(object):
def __init__(self, amount: float, status: str, buy_order: str, session_id: str,
card_detail: CardDetail, accounting_date: str, transaction_date: str, authorization_code: str,
Expand Down Expand Up @@ -119,6 +120,23 @@ def __repr__(self):
self.response_code)


class TransactionCaptureResponse(object):
def __init__(self, authorization_code: str, authorization_date: str, captured_amount: float, response_code: str):
self.authorization_code = authorization_code
self.authorization_date = authorization_date
self.captured_amount = captured_amount
self.response_code = response_code

def __repr__(self):
return """
authorization_code: {},
authorization_date: {},
captured_amount: {},
response_code: {}
""".format(self.authorization_code, self.authorization_date, self.captured_amount,
self.response_code)


class TransactionInstallmentsResponse(object):
def __init__(self, installments_amount: float, id_query_installments: str, deferred_periods: str):
self.installments_amount = installments_amount
Expand All @@ -131,3 +149,4 @@ def __repr__(self):
id_query_installments: {},
deferred_periods: {}
""".format(self.installments_amount, self.id_query_installments, self.deferred_periods)

13 changes: 13 additions & 0 deletions transbank/transaccion_completa/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,16 @@ class RefundTransactionResponseSchema(Schema):
nullified_amount = fields.Raw()
balance = fields.Raw()
response_code = fields.Raw()


class CaptureTransactionRequestSchema(Schema):
buy_order = fields.Str()
authorization_code = fields.Str()
capture_amount = fields.Float()


class CaptureTransactionResponseSchema(Schema):
authorization_code = fields.Str()
authorization_date = fields.Str()
captured_amount = fields.Float()
response_code = fields.Raw()
23 changes: 20 additions & 3 deletions transbank/transaccion_completa/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
from transbank.error.transaction_commit_error import TransactionCommitError
from transbank.error.transaction_refund_error import TransactionRefundError
from transbank.error.transaction_status_error import TransactionStatusError
from transbank.error.transaction_capture_error import TransactionCaptureError
from transbank.error.transaction_installments_error import TransactionInstallmentsError
from transbank.transaccion_completa.request import TransactionCreateRequest, TransactionCommitRequest, \
TransactionStatusRequest, TransactionRefundRequest, TransactionInstallmentsRequest
TransactionStatusRequest, TransactionRefundRequest, TransactionCaptureRequest, TransactionInstallmentsRequest
from transbank.transaccion_completa.response import TransactionCreateResponse, TransactionCommitResponse, \
TransactionStatusResponse, TransactionRefundResponse, TransactionInstallmentsResponse
TransactionStatusResponse, TransactionRefundResponse, TransactionCaptureResponse, TransactionInstallmentsResponse
from transbank.transaccion_completa.schema import CreateTransactionRequestSchema, CreateTransactionResponseSchema, \
CommitTransactionRequestSchema, CommitTransactionResponseSchema, InstallmentsTransactionRequestSchema, \
InstallmentsTransactionResponseSchema, RefundTransactionRequestSchema, RefundTransactionResponseSchema
InstallmentsTransactionResponseSchema, RefundTransactionRequestSchema, RefundTransactionResponseSchema, \
CaptureTransactionRequestSchema, CaptureTransactionResponseSchema


class Transaction(object):
Expand Down Expand Up @@ -88,6 +90,21 @@ def refund(cls, token: str, amount: str, options: Options = None):
return TransactionRefundResponse(**response_dict)
raise TransactionRefundError(message=response_dict["error_message"])

@classmethod
def capture(cls, token: str, buy_order: str, authorization_code: str, capture_amount: float, options: Options = None):
options = cls.build_options(options)
endpoint = '{}/{}/capture'.format(cls.__base_url(options.integration_type), token)
request = TransactionCaptureRequest(buy_order=buy_order, authorization_code=authorization_code,
capture_amount=capture_amount)
response = requests.put(endpoint, data=CaptureTransactionRequestSchema().dumps(request).data,
headers=HeadersBuilder.build(options))
response_json = response.text
response_dict = CaptureTransactionResponseSchema().loads(response_json).data
if response.status_code in range (200,209):
return TransactionCaptureResponse(**response_dict)
raise TransactionCaptureError(message=response_dict["error_message"])


@classmethod
def installments(cls, token: str, installments_number: float, options: Options = None):
options = cls.build_options(options)
Expand Down
8 changes: 8 additions & 0 deletions transbank/transaccion_completa_mall/request/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def __init__(self, commerce_code: str, buy_order: str, amount: float):
self.amount = amount


class TransactionCaptureRequest(object):
def __init__(self, commerce_code: str, buy_order: str, authorization_code: str, capture_amount: float):
self.commerce_code = commerce_code
self.buy_order= buy_order
self.authorization_code = authorization_code
self.capture_amount = capture_amount


class TransactionInstallmentsRequest(object):
def __init__(self, installments_number: float, buy_order: str, commerce_code: str):
self.installments_number = installments_number
Expand Down
17 changes: 17 additions & 0 deletions transbank/transaccion_completa_mall/response/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ def __repr__(self):
self.response_code)


class TransactionCaptureResponse(object):
def __init__(self, authorization_code: str, authorization_date: str,
captured_amount: float, response_code: str):
self.authorization_code = authorization_code
self.authorization_date = authorization_date
self.captured_amount = captured_amount
self.response_code = response_code

def __repr__(self):
return """
authorization_code: {},
authorization_date: {},
captured_amount: {},
response_code: {}
""".format(self.authorization_code, self.authorization_date, self.captured_amount, self.response_code)


class TransactionInstallmentsResponse(object):
def __init__(self, installments_amount: float, id_query_installments: str, deferred_periods: str):
self.installments_amount = installments_amount
Expand Down
14 changes: 14 additions & 0 deletions transbank/transaccion_completa_mall/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,17 @@ class RefundTransactionResponseSchema(Schema):
nullified_amount = fields.Raw()
balance = fields.Raw()
response_code = fields.Raw()


class CaptureTransactionRequestSchema(Schema):
commerce_code = fields.Str()
buy_order = fields.Str()
authorization_code = fields.Str()
capture_amount = fields.Float()


class CaptureTransactionResponseSchema(Schema):
authorization_code = fields.Str()
authorization_date = fields.Str()
captured_amount = fields.Float()
response_code = fields.Raw()
24 changes: 20 additions & 4 deletions transbank/transaccion_completa_mall/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
from transbank.error.transaction_commit_error import TransactionCommitError
from transbank.error.transaction_refund_error import TransactionRefundError
from transbank.error.transaction_status_error import TransactionStatusError
from transbank.error.transaction_capture_error import TransactionCaptureError
from transbank.error.transaction_installments_error import TransactionInstallmentsError
from transbank.transaccion_completa_mall.request import TransactionCreateRequest, TransactionCommitRequest, \
TransactionStatusRequest, TransactionRefundRequest, TransactionInstallmentsRequest
TransactionStatusRequest, TransactionRefundRequest, TransactionInstallmentsRequest, TransactionCaptureRequest
from transbank.transaccion_completa_mall.response import TransactionCreateResponse, TransactionCommitResponse, \
TransactionStatusResponse, TransactionRefundResponse, TransactionInstallmentsResponse
TransactionStatusResponse, TransactionRefundResponse, TransactionCaptureResponse, TransactionInstallmentsResponse
from transbank.transaccion_completa_mall.schema import CreateTransactionRequestSchema, CreateTransactionResponseSchema, \
CommitTransactionRequestSchema, CommitTransactionResponseSchema, InstallmentsTransactionRequestSchema, \
InstallmentsTransactionResponseSchema, RefundTransactionRequestSchema, RefundTransactionResponseSchema, \
StatusTransactionResponseSchema
StatusTransactionResponseSchema, CaptureTransactionRequestSchema, CaptureTransactionResponseSchema


class Transaction(object):
Expand Down Expand Up @@ -77,7 +78,7 @@ def status(cls, token: str, options: Options = None):
raise TransactionStatusError(message=response_dict["error_message"])

@classmethod
def refund(cls, token: str, child_buy_order: str, child_commerce_code:str, amount: str, options: Options = None):
def refund(cls, token: str, child_buy_order: str, child_commerce_code: str, amount: str, options: Options = None):
options = cls.build_options(options)
endpoint = '{}/{}/refunds'.format(cls.__base_url(options.integration_type), token)
request = TransactionRefundRequest(buy_order=child_buy_order, commerce_code=child_commerce_code, amount=amount)
Expand All @@ -89,6 +90,21 @@ def refund(cls, token: str, child_buy_order: str, child_commerce_code:str, amoun
return TransactionRefundResponse(**response_dict)
raise TransactionRefundError(message=response_dict["error_message"])

@classmethod
def capture(cls, token: str, child_commerce_code: str, child_buy_order: str, authorization_code: str,
capture_amount: float, options: Options = None):
options = cls.build_options(options)
endpoint = '{}/{}/capture'.format(cls.__base_url(options.integration_type), token)
request = TransactionCaptureRequest(commerce_code=child_commerce_code, buy_order=child_buy_order,
authorization_code=authorization_code, capture_amount=capture_amount)
response = requests.put(endpoint, data=CaptureTransactionRequestSchema().dumps(request).data,
headers=HeadersBuilder.build(options))
response_json = response.text
response_dict = CaptureTransactionResponseSchema().loads(response_json).data
if response.status_code in (200, 299):
return TransactionCaptureResponse(**response_dict)
raise TransactionCaptureError(message=response_dict["error_message"])

@classmethod
def installments(cls, token: str, details: list, options: Options = None):
options = cls.build_options(options)
Expand Down

0 comments on commit d7fea5a

Please sign in to comment.