[ADD]:Added Upstream patch for payment_stripe

This commit is contained in:
sheetalPatil 2018-07-09 19:13:24 +05:30
parent 623614afff
commit 0708710ecf
4 changed files with 15 additions and 29 deletions

View File

@ -3,3 +3,4 @@
from . import models from . import models
from . import controllers from . import controllers
from flectra.addons.payment.models.payment_acquirer import create_missing_journal_for_acquirers

View File

@ -15,4 +15,5 @@
], ],
'images': ['static/description/icon.png'], 'images': ['static/description/icon.png'],
'installable': True, 'installable': True,
'post_init_hook': 'create_missing_journal_for_acquirers',
} }

View File

@ -8,6 +8,7 @@ from flectra import api, fields, models, _
from flectra.addons.payment.models.payment_acquirer import ValidationError from flectra.addons.payment.models.payment_acquirer import ValidationError
from flectra.exceptions import UserError from flectra.exceptions import UserError
from flectra.tools.safe_eval import safe_eval from flectra.tools.safe_eval import safe_eval
from flectra.tools.float_utils import float_round
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -41,12 +42,12 @@ class PaymentAcquirerStripe(models.Model):
stripe_tx_values = dict(tx_values) stripe_tx_values = dict(tx_values)
temp_stripe_tx_values = { temp_stripe_tx_values = {
'company': self.company_id.name, 'company': self.company_id.name,
'amount': tx_values.get('amount'), 'amount': tx_values['amount'], # Mandatory
'currency': tx_values.get('currency') and tx_values.get('currency').name or '', 'currency': tx_values['currency'].name, # Mandatory anyway
'currency_id': tx_values.get('currency') and tx_values.get('currency').id or '', 'currency_id': tx_values['currency'].id, # same here
'address_line1': tx_values.get('partner_address'), 'address_line1': tx_values.get('partner_address'), # Any info of the partner is not mandatory
'address_city': tx_values.get('partner_city'), 'address_city': tx_values.get('partner_city'),
'address_country': tx_values.get('partner_country') and tx_values['partner_country'].name or '', 'address_country': tx_values.get('partner_country') and tx_values.get('partner_country').name or '',
'email': tx_values.get('partner_email'), 'email': tx_values.get('partner_email'),
'address_zip': tx_values.get('partner_zip'), 'address_zip': tx_values.get('partner_zip'),
'name': tx_values.get('partner_name'), 'name': tx_values.get('partner_name'),
@ -106,7 +107,7 @@ class PaymentTransactionStripe(models.Model):
def _create_stripe_charge(self, acquirer_ref=None, tokenid=None, email=None): def _create_stripe_charge(self, acquirer_ref=None, tokenid=None, email=None):
api_url_charge = 'https://%s/charges' % (self.acquirer_id._get_stripe_api_url()) api_url_charge = 'https://%s/charges' % (self.acquirer_id._get_stripe_api_url())
charge_params = { charge_params = {
'amount': int(self.amount if self.currency_id.name in INT_CURRENCIES else self.amount*100), 'amount': int(self.amount if self.currency_id.name in INT_CURRENCIES else float_round(self.amount * 100, 2)),
'currency': self.currency_id.name, 'currency': self.currency_id.name,
'metadata[reference]': self.reference, 'metadata[reference]': self.reference,
'description': self.reference, 'description': self.reference,
@ -126,7 +127,7 @@ class PaymentTransactionStripe(models.Model):
@api.multi @api.multi
def stripe_s2s_do_transaction(self, **kwargs): def stripe_s2s_do_transaction(self, **kwargs):
self.ensure_one() self.ensure_one()
result = self._create_stripe_charge(acquirer_ref=self.payment_token_id.acquirer_ref) result = self._create_stripe_charge(acquirer_ref=self.payment_token_id.acquirer_ref, email=self.partner_email)
return self._stripe_s2s_validate_tree(result) return self._stripe_s2s_validate_tree(result)
@ -135,7 +136,7 @@ class PaymentTransactionStripe(models.Model):
refund_params = { refund_params = {
'charge': self.acquirer_reference, 'charge': self.acquirer_reference,
'amount': int(self.amount*100), # by default, stripe refund the full amount (we don't really need to specify the value) 'amount': int(float_round(self.amount * 100, 2)), # by default, stripe refund the full amount (we don't really need to specify the value)
'metadata[reference]': self.reference, 'metadata[reference]': self.reference,
} }

View File

@ -62,31 +62,14 @@ class StripeTest(StripeCommon):
# ---------------------------------------- # ----------------------------------------
# Test: button direct rendering # Test: button direct rendering
# ---------------------------------------- # ----------------------------------------
form_values = {
'amount': 320.0,
'currency': 'EUR',
'address_line1': 'Huge Street 2/543',
'address_city': 'Sin City',
'address_country': 'Belgium',
'email': 'norbert.buyer@example.com',
'address_zip': '1000',
'name': 'Norbert Buyer',
'phone': '0032 12 34 56 78'
}
# render the button # render the button
res = self.stripe.render('SO404', 320.0, self.currency_euro.id, values=self.buyer_values) res = self.stripe.render('SO404', 320.0, self.currency_euro.id, values=self.buyer_values).decode('utf-8')
post_url = "https://checkout.stripe.com/checkout.js" popup_script_src = 'script src="https://checkout.stripe.com/checkout.js"'
email = "norbert.buyer@example.com"
# check form result # check form result
if "https://checkout.stripe.com/checkout.js" in res[0]: self.assertIn(popup_script_src, res, "Stripe: popup script not found in template render")
self.assertEqual(post_url, 'https://checkout.stripe.com/checkout.js', 'Stripe: wrong form POST url')
# Generated and received # Generated and received
if email in res[0]: self.assertIn(self.buyer_values.get('partner_email'), res, 'Stripe: email input not found in rendered template')
self.assertEqual(
email, form_values.get('email'),
'Stripe: wrong value for input %s: received %s instead of %s' % (email, email, form_values.get('email'))
)
@unittest.skip("Stripe test disabled: We do not want to overload Stripe with runbot's requests") @unittest.skip("Stripe test disabled: We do not want to overload Stripe with runbot's requests")
def test_30_stripe_form_management(self): def test_30_stripe_form_management(self):