[CLN] payment_stripe: cleaning and guidelines
As this module is already in new API only small linting is performed.
This commit is contained in:
@@ -19,19 +19,15 @@ STRIPE_HEADERS = {'Stripe-Version': '2016-03-07'}
|
||||
class PaymentAcquirerStripe(models.Model):
|
||||
_inherit = 'payment.acquirer'
|
||||
|
||||
provider = fields.Selection(selection_add=[('stripe', 'Stripe')])
|
||||
stripe_secret_key = fields.Char(required_if_provider='stripe')
|
||||
stripe_publishable_key = fields.Char(required_if_provider='stripe')
|
||||
stripe_image_url = fields.Char("Checkout Image URL",
|
||||
stripe_image_url = fields.Char(
|
||||
"Checkout Image URL",
|
||||
help="A relative or absolute URL pointing to a square image of your "
|
||||
"brand or product. As defined in your Stripe profile. See: "
|
||||
"https://stripe.com/docs/checkout")
|
||||
|
||||
@api.model
|
||||
def _get_providers(self):
|
||||
providers = super(PaymentAcquirerStripe, self)._get_providers()
|
||||
providers.append(['stripe', 'Stripe'])
|
||||
return providers
|
||||
|
||||
@api.multi
|
||||
def stripe_form_generate_values(self, tx_values):
|
||||
self.ensure_one()
|
||||
|
||||
@@ -12,9 +12,7 @@ class StripeCommon(PaymentAcquirerCommon):
|
||||
|
||||
def setUp(self):
|
||||
super(StripeCommon, self).setUp()
|
||||
self.currency_euro = self.env['res.currency'].search([('name', '=', 'EUR')], limit=1)
|
||||
# get the stripe account
|
||||
self.stripe_id = self.env.ref('payment.payment_acquirer_stripe').id
|
||||
self.stripe = self.env.ref('payment.payment_acquirer_stripe')
|
||||
|
||||
|
||||
@odoo.tests.common.at_install(True)
|
||||
@@ -22,18 +20,17 @@ class StripeCommon(PaymentAcquirerCommon):
|
||||
class StripeTest(StripeCommon):
|
||||
|
||||
def test_10_stripe_s2s(self):
|
||||
stripe = self.env['payment.acquirer'].browse(self.stripe_id)
|
||||
self.assertEqual(stripe.environment, 'test', 'test without test environment')
|
||||
self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
|
||||
|
||||
# Add Stripe credentials
|
||||
stripe.write({
|
||||
self.stripe.write({
|
||||
'stripe_secret_key': 'sk_test_bldAlqh1U24L5HtRF9mBFpK7',
|
||||
'stripe_publishable_key': 'pk_test_0TKSyYSZS9AcS4keZ2cxQQCW',
|
||||
})
|
||||
|
||||
# Create payment meethod for Stripe
|
||||
payment_token = self.env['payment.token'].create({
|
||||
'acquirer_id': self.stripe_id,
|
||||
'acquirer_id': self.stripe.id,
|
||||
'partner_id': self.buyer_id,
|
||||
'cc_number': '4242424242424242',
|
||||
'cc_expiry': '02 / 26',
|
||||
@@ -46,7 +43,7 @@ class StripeTest(StripeCommon):
|
||||
tx = self.env['payment.transaction'].create({
|
||||
'reference': 'test_ref_%s' % fields.date.today(),
|
||||
'currency_id': self.currency_euro.id,
|
||||
'acquirer_id': self.stripe_id,
|
||||
'acquirer_id': self.stripe.id,
|
||||
'partner_id': self.buyer_id,
|
||||
'payment_token_id': payment_token.id,
|
||||
'type': 'server2server',
|
||||
@@ -58,8 +55,7 @@ class StripeTest(StripeCommon):
|
||||
self.assertEqual(tx.state, 'done', 'Stripe: Transcation has been discarded.')
|
||||
|
||||
def test_20_stripe_form_render(self):
|
||||
stripe = self.env['payment.acquirer'].browse(self.stripe_id)
|
||||
self.assertEqual(stripe.environment, 'test', 'test without test environment')
|
||||
self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
|
||||
|
||||
# ----------------------------------------
|
||||
# Test: button direct rendering
|
||||
@@ -77,7 +73,7 @@ class StripeTest(StripeCommon):
|
||||
}
|
||||
|
||||
# render the button
|
||||
res = 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)
|
||||
post_url = "https://checkout.stripe.com/checkout.js"
|
||||
email = "norbert.buyer@example.com"
|
||||
# check form result
|
||||
@@ -91,8 +87,7 @@ class StripeTest(StripeCommon):
|
||||
)
|
||||
|
||||
def test_30_stripe_form_management(self):
|
||||
stripe = self.env['payment.acquirer'].browse(self.stripe_id)
|
||||
self.assertEqual(stripe.environment, 'test', 'test without test environment')
|
||||
self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
|
||||
|
||||
# typical data posted by Stripe after client has successfully paid
|
||||
stripe_post_data = {
|
||||
@@ -153,11 +148,11 @@ class StripeTest(StripeCommon):
|
||||
|
||||
tx = self.env['payment.transaction'].create({
|
||||
'amount': 4700,
|
||||
'acquirer_id': self.stripe_id,
|
||||
'acquirer_id': self.stripe.id,
|
||||
'currency_id': self.currency_euro.id,
|
||||
'reference': 'SO100',
|
||||
'partner_name': 'Norbert Buyer',
|
||||
'partner_country_id': self.country_france_id})
|
||||
'partner_country_id': self.country_france.id})
|
||||
|
||||
# validate it
|
||||
tx.form_feedback(stripe_post_data, 'stripe')
|
||||
@@ -168,7 +163,7 @@ class StripeTest(StripeCommon):
|
||||
# simulate an error
|
||||
stripe_post_data['status'] = 'error'
|
||||
stripe_post_data.update({u'error': {u'message': u"Your card's expiration year is invalid.", u'code': u'invalid_expiry_year', u'type': u'card_error', u'param': u'exp_year'}})
|
||||
with mute_logger('openerp.addons.payment_stripe.models.payment_transaction'):
|
||||
with mute_logger('openerp.addons.payment_stripe.models.payment'):
|
||||
tx.form_feedback(stripe_post_data, 'stripe')
|
||||
# check state
|
||||
self.assertEqual(tx.state, 'error', 'Stipe: erroneous validation did not put tx into error state')
|
||||
|
||||
Reference in New Issue
Block a user