Files
odoo_source/addons/payment_stripe/tests/test_stripe.py
T
qdp-odoo 01216345e2 [REF] account,payment(_*),sale*: downgrade transactions into debug items
It was very confusing for the user to distinct account.payment and payment.transaction. From now on, the transactions are
technical objects and, in the backend, we only refer to it in log messages (Front end will be adapted in the same fashion
later on). They are hidden in debug mode in accounting\configuration\payments as their purpose is now purely technical/log

This commit also aims to reduce the gap between the accounting app and the transactions: account.payment objects are
created/validated upon completion of transaction.

To ease the capture/voiding of pending transactions, the related buttons are now displayed directly on the SO/invoice
instead of the transactions.

Was task: https://www.odoo.com/web#id=35857&view_type=form&model=project.task&action=333&active_id=967&menu_id=4720
Was PR #24043

[FIX] add domain based on journal to payment tokens

Was opw: https://www.odoo.com/web?debug#id=1828206&view_type=form&model=project.task&menu_id=5200
2018-05-23 15:44:55 +02:00

172 lines
7.0 KiB
Python

# -*- coding: utf-8 -*-
import odoo
from odoo import fields
from odoo.addons.payment.tests.common import PaymentAcquirerCommon
from odoo.tools import mute_logger
class StripeCommon(PaymentAcquirerCommon):
def setUp(self):
super(StripeCommon, self).setUp()
self.stripe = self.env.ref('payment.payment_acquirer_stripe')
@odoo.tests.tagged('post_install', '-at_install', '-standard', 'external')
class StripeTest(StripeCommon):
def test_10_stripe_s2s(self):
self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
# Add Stripe credentials
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,
'partner_id': self.buyer_id,
'cc_number': '4242424242424242',
'cc_expiry': '02 / 26',
'cc_brand': 'visa',
'cvc': '111',
'cc_holder_name': 'Johndoe',
})
# Create transaction
tx = self.env['payment.transaction'].create({
'reference': 'test_ref_%s' % fields.date.today(),
'currency_id': self.currency_euro.id,
'acquirer_id': self.stripe.id,
'partner_id': self.buyer_id,
'payment_token_id': payment_token.id,
'type': 'server2server',
'amount': 115.0
})
tx.stripe_s2s_do_transaction()
# Check state
self.assertEqual(tx.state, 'done', 'Stripe: Transcation has been discarded.')
def test_20_stripe_form_render(self):
self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
# ----------------------------------------
# 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
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
if "https://checkout.stripe.com/checkout.js" in res[0]:
self.assertEqual(post_url, 'https://checkout.stripe.com/checkout.js', 'Stripe: wrong form POST url')
# Generated and received
if email in res[0]:
self.assertEqual(
email, form_values.get('email'),
'Stripe: wrong value for input %s: received %s instead of %s' % (email, email, form_values.get('email'))
)
def test_30_stripe_form_management(self):
self.assertEqual(self.stripe.environment, 'test', 'test without test environment')
# typical data posted by Stripe after client has successfully paid
stripe_post_data = {
u'amount': 4700,
u'amount_refunded': 0,
u'application_fee': None,
u'balance_transaction': u'txn_172xfnGMfVJxozLwssrsQZyT',
u'captured': True,
u'created': 1446529775,
u'currency': u'eur',
u'customer': None,
u'description': None,
u'destination': None,
u'dispute': None,
u'failure_code': None,
u'failure_message': None,
u'fraud_details': {},
u'id': u'ch_172xfnGMfVJxozLwEjSfpfxD',
u'invoice': None,
u'livemode': False,
u'metadata': {u'reference': u'SO100'},
u'object': u'charge',
u'paid': True,
u'receipt_email': None,
u'receipt_number': None,
u'refunded': False,
u'refunds': {u'data': [],
u'has_more': False,
u'object': u'list',
u'total_count': 0,
u'url': u'/v1/charges/ch_172xfnGMfVJxozLwEjSfpfxD/refunds'},
u'shipping': None,
u'source': {u'address_city': None,
u'address_country': None,
u'address_line1': None,
u'address_line1_check': None,
u'address_line2': None,
u'address_state': None,
u'address_zip': None,
u'address_zip_check': None,
u'brand': u'Visa',
u'country': u'US',
u'customer': None,
u'cvc_check': u'pass',
u'dynamic_last4': None,
u'exp_month': 2,
u'exp_year': 2022,
u'fingerprint': u'9tJA9bUEuvEb3Ell',
u'funding': u'credit',
u'id': u'card_172xfjGMfVJxozLw1QO6gYNM',
u'last4': u'4242',
u'metadata': {},
u'name': u'norbert.buyer@example.com',
u'object': u'card',
u'tokenization_method': None},
u'statement_descriptor': None,
u'status': u'succeeded'}
tx = self.env['payment.transaction'].create({
'amount': 4700,
'acquirer_id': self.stripe.id,
'currency_id': self.currency_euro.id,
'reference': 'SO100-1',
'partner_name': 'Norbert Buyer',
'partner_country_id': self.country_france.id})
# validate it
tx.form_feedback(stripe_post_data, 'stripe')
self.assertEqual(tx.state, 'done', 'Stripe: validation did not put tx into done state')
self.assertEqual(tx.acquirer_reference, stripe_post_data.get('id'), 'Stripe: validation did not update tx id')
# reset tx
tx = self.env['payment.transaction'].create({
'amount': 4700,
'acquirer_id': self.stripe.id,
'currency_id': self.currency_euro.id,
'reference': 'SO100-2',
'partner_name': 'Norbert Buyer',
'partner_country_id': self.country_france.id})
# 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('odoo.addons.payment_stripe.models.payment'):
tx.form_feedback(stripe_post_data, 'stripe')
# check state
self.assertEqual(tx.state, 'cancel', 'Stipe: erroneous validation did not put tx into error state')