diff options
| author | tbe-odoo <tbe@odoo.com> | 2017-07-28 15:52:34 +0200 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2017-08-14 08:30:59 +0200 |
| commit | 2df9c22d80be82b4ed7ffcd79f858e46c34e6479 (patch) | |
| tree | 5f3d7d68c4fc4e461e1a3f235266b14c23d0340a /addons/payment_authorize/models/authorize_request.py | |
| parent | c089d39a668fa6ab1f5d7867747da19d0b75f035 (diff) | |
[IMP] Payments & subscriptions: Improved Payments
- When registering a payment token, validating it using a payment of a small amount (~1.50€) followed by a refund allows ensuring
that the payment method is valid (i.e. checksumming the card number simple ensure the number is valid but not that the card exists).
This commit introduces a generic approach that must be implemented for each acquirer that has tokenization support.
This commit also introduces a generic payment token registration/usage template that can be adapted according to one's need.
- Introducing a new payment form that handles payment, deletion and adding payment method (only for server2server for the moment).
- On /my/payment_method, changed strings 'Payment Acquirers' to 'Payment Methods' which is more clear.
- Stripe can now be used to pay subscriptions.
Diffstat (limited to 'addons/payment_authorize/models/authorize_request.py')
| -rw-r--r-- | addons/payment_authorize/models/authorize_request.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/addons/payment_authorize/models/authorize_request.py b/addons/payment_authorize/models/authorize_request.py index d8191dfc34c..fcfab1e3ac2 100644 --- a/addons/payment_authorize/models/authorize_request.py +++ b/addons/payment_authorize/models/authorize_request.py @@ -163,6 +163,33 @@ class AuthorizeAPI(): res['name'] = response_profile.find('paymentProfile/payment/creditCard/cardNumber').text return res + def credit(self, token, amount, transaction_id): + """ Refund a payment for the given amount. + + :param record token: the payment.token record that must be refunded. + :param str amount: transaction amount + :param str transaction_id: the reference of the transacation that is going to be refunded. + + :return: a dict containing the response code, transaction id and transaction type + :rtype: dict + """ + root = self._base_tree('createTransactionRequest') + tx = etree.SubElement(root, "transactionRequest") + etree.SubElement(tx, "transactionType").text = "refundTransaction" + etree.SubElement(tx, "amount").text = str(amount) + payment = etree.SubElement(tx, "payment") + credit_card = etree.SubElement(payment, "creditCard") + idx = token.name.find(' - ') + etree.SubElement(credit_card, "cardNumber").text = token.name[idx-4:idx] # shitty hack, but that's the only way to get the 4 last digits + etree.SubElement(credit_card, "expirationDate").text = "XXXX" + etree.SubElement(tx, "refTransId").text = transaction_id + response = self._authorize_request(root) + res = dict() + res['x_response_code'] = response.find('transactionResponse/responseCode').text + res['x_trans_id'] = transaction_id + res['x_type'] = 'refund' + return res + # Transaction management def auth_and_capture(self, token, amount, reference): """Authorize and capture a payment for the given amount. |
