summaryrefslogtreecommitdiff
path: root/addons/payment_alipay
diff options
context:
space:
mode:
authorVictor Feyens <vfe@odoo.com>2019-07-18 13:56:34 +0000
committerVictor Feyens <vfe@odoo.com>2019-08-12 08:45:50 +0000
commitf0e059e6010605b5cce2a3055ed3aaf7730534fa (patch)
treea90dce7fae7b1bb6f04cd48abcae06ff74b36f71 /addons/payment_alipay
parent611fde6c8828d7d89b8c7f90b60484c58debcf73 (diff)
[REF] payment* : state based publishing
Replace website_published and environment by a generic state on payment.acquirer Payment acquirers aren't enabled by default. When setting their state to 'enabled' or 'test', it is verified the required fields for the provider are set.
Diffstat (limited to 'addons/payment_alipay')
-rw-r--r--addons/payment_alipay/controllers/main.py2
-rw-r--r--addons/payment_alipay/data/payment_acquirer_data.xml4
-rw-r--r--addons/payment_alipay/models/payment.py4
-rw-r--r--addons/payment_alipay/tests/test_alipay.py14
4 files changed, 14 insertions, 10 deletions
diff --git a/addons/payment_alipay/controllers/main.py b/addons/payment_alipay/controllers/main.py
index 14fc05efca8..5763313b1a9 100644
--- a/addons/payment_alipay/controllers/main.py
+++ b/addons/payment_alipay/controllers/main.py
@@ -40,7 +40,7 @@ class AlipayController(http.Controller):
'partner': alipay.alipay_merchant_partner_id,
'notify_id': post['notify_id']
}
- response = requests.post(alipay._get_alipay_urls(alipay.environment), val)
+ response = requests.post(alipay.alipay_get_form_action_url(), val)
response.raise_for_status()
_logger.info('Validate alipay Notification %s' % response.text)
# After program is executed, the page must print “success” (without quote). If not, Alipay server would keep re-sending notification, until over 24 hour 22 minutes Generally, there are 8 notifications within 25 hours (Frequency: 2m,10m,15m,1h,2h,6h,15h)
diff --git a/addons/payment_alipay/data/payment_acquirer_data.xml b/addons/payment_alipay/data/payment_acquirer_data.xml
index a608788e5fa..88930847eca 100644
--- a/addons/payment_alipay/data/payment_acquirer_data.xml
+++ b/addons/payment_alipay/data/payment_acquirer_data.xml
@@ -5,14 +5,10 @@
<field name="provider">alipay</field>
<field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="alipay_form"/>
- <field name="environment">test</field>
<field name="pre_msg" type="html">
<p>
You will be redirected to the Alipay website after clicking on the payment button.
</p>
</field>
- <field name="alipay_merchant_partner_id">dummy</field>
- <field name="alipay_md5_signature_key">dummy</field>
- <field name="alipay_seller_email">dummy</field>
</record>
</odoo>
diff --git a/addons/payment_alipay/models/payment.py b/addons/payment_alipay/models/payment.py
index d1fcf343cb5..e56dcae8f4f 100644
--- a/addons/payment_alipay/models/payment.py
+++ b/addons/payment_alipay/models/payment.py
@@ -110,7 +110,9 @@ class PaymentAcquirer(models.Model):
return values
def alipay_get_form_action_url(self):
- return self._get_alipay_urls(self.environment)
+ self.ensure_one()
+ environment = 'prod' if self.state == 'enabled' else 'test'
+ return self._get_alipay_urls(environment)
class PaymentTransaction(models.Model):
diff --git a/addons/payment_alipay/tests/test_alipay.py b/addons/payment_alipay/tests/test_alipay.py
index 511231dd8f1..51e8e22fbfb 100644
--- a/addons/payment_alipay/tests/test_alipay.py
+++ b/addons/payment_alipay/tests/test_alipay.py
@@ -22,10 +22,16 @@ class AlipayTest(PaymentAcquirerCommon):
('active', '=', True),
('active', '=', False)], limit=1)
self.alipay = self.env.ref('payment.payment_acquirer_alipay')
+ self.alipay.write({
+ 'alipay_merchant_partner_id': 'dummy',
+ 'alipay_md5_signature_key': 'dummy',
+ 'alipay_seller_email': 'dummy',
+ 'state': 'test',
+ })
def test_10_alipay_form_render(self):
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
- self.assertEqual(self.alipay.environment, 'test', 'test without test environment')
+ self.assertEqual(self.alipay.state, 'test', 'test without test environment')
# ----------------------------------------
# Test: button direct rendering
@@ -73,7 +79,7 @@ class AlipayTest(PaymentAcquirerCommon):
self.assertEqual(form_input.get('value'), form_values[form_input.get('name')], 'alipay: wrong value for input %s: received %s instead of %s' % (form_input.get('name'), form_input.get('value'), form_values[form_input.get('name')]))
def test_11_alipay_form_with_fees(self):
- self.assertEqual(self.alipay.environment, 'test', 'test without test environment')
+ self.assertEqual(self.alipay.state, 'test', 'test without test environment')
# update acquirer: compute fees
self.alipay.write({
@@ -106,7 +112,7 @@ class AlipayTest(PaymentAcquirerCommon):
self._test_20_alipay_form_management()
def _test_20_alipay_form_management(self):
- self.assertEqual(self.alipay.environment, 'test', 'test without test environment')
+ self.assertEqual(self.alipay.state, 'test', 'test without test environment')
# typical data posted by alipay after client has successfully paid
alipay_post_data = {
@@ -192,4 +198,4 @@ class AlipayTest(PaymentAcquirerCommon):
'currency_id': self.currency_yuan.id,
'reference': 'test_ref_2',
'partner_country_id': self.country_france.id
- }) \ No newline at end of file
+ })