diff options
| author | Damien Bouvy <dbo@odoo.com> | 2016-09-01 13:07:12 +0200 |
|---|---|---|
| committer | Damien Bouvy <dbo@odoo.com> | 2016-09-01 15:58:41 +0200 |
| commit | ffd527d0273197925102175feb95d4a6f4fcd8d5 (patch) | |
| tree | 80281badff239c5d4a6e0a4cc23bb75eb558d4fd /addons/payment_authorize/models/authorize_request.py | |
| parent | d9c9d0c96b2aaf66da476adae8f8e935bd7dfebf (diff) | |
[IMP] payment, payment_*: add/improve tokenization support
This commit improves the tokenization process, allowing users
to set the acquirer to save payment data never, always or letting
the customer decide (only implemented in ecommerce for now).
Support for tokenization is improved for Ogone and Authorize.net
This commits also factorizes advanced payment features support
(authorization, tokenization, fees computation) in a generic method
overriden by every provider to specifiy which features are supported.
This process can be used in views to hide/show fields depending on
feature support or in constraint checks.
Diffstat (limited to 'addons/payment_authorize/models/authorize_request.py')
| -rw-r--r-- | addons/payment_authorize/models/authorize_request.py | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/addons/payment_authorize/models/authorize_request.py b/addons/payment_authorize/models/authorize_request.py index e94c4e1c484..28cba8db301 100644 --- a/addons/payment_authorize/models/authorize_request.py +++ b/addons/payment_authorize/models/authorize_request.py @@ -126,6 +126,42 @@ class AuthorizeAPI(): res['payment_profile_id'] = response.find('customerPaymentProfileIdList/numericString').text return res + def create_customer_profile_from_tx(self, partner, transaction_id): + """Create an Auth.net payment/customer profile from an existing transaction. + + Creates a customer profile for the partner/credit card combination and links + a corresponding payment profile to it. Note that a single partner in the Odoo + database can have multiple customer profiles in Authorize.net (i.e. a customer + profile is created for every res.partner/payment.token couple). + + Note that this function makes 2 calls to the authorize api, since we need to + obtain a partial cardnumber to generate a meaningful payment.token name. + + :param record partner: the res.partner record of the customer + :param str transaction_id: id of the authorized transaction in the + Authorize.net backend + + :return: a dict containing the profile_id and payment_profile_id of the + newly created customer profile and payment profile as well as the + last digits of the card number + :rtype: dict + """ + root = self._base_tree('createCustomerProfileFromTransactionRequest') + etree.SubElement(root, "transId").text = transaction_id + customer = etree.SubElement(root, "customer") + etree.SubElement(customer, "merchantCustomerId").text = 'ODOO-%s-%s' % (partner.id, uuid4().hex[:8]) + etree.SubElement(customer, "email").text = partner.email + response = self._authorize_request(root) + res = dict() + res['profile_id'] = response.find('customerProfileId').text + res['payment_profile_id'] = response.find('customerPaymentProfileIdList/numericString').text + root_profile = self._base_tree('getCustomerPaymentProfileRequest') + etree.SubElement(root_profile, "customerProfileId").text = res['profile_id'] + etree.SubElement(root_profile, "customerPaymentProfileId").text = res['payment_profile_id'] + response_profile = self._authorize_request(root_profile) + res['name'] = response_profile.find('paymentProfile/payment/creditCard/cardNumber').text + return res + # Transaction management def auth_and_capture(self, token, amount, reference): """Authorize and capture a payment for the given amount. @@ -193,7 +229,7 @@ class AuthorizeAPI(): Capture a previsouly authorized payment. Note that the amount is required even though we do not support partial capture. - :param str transaction_id: the id of the authorized transaction in the + :param str transaction_id: id of the authorized transaction in the Authorize.net backend :param str amount: transaction amount (up to 15 digits with decimal point) |
