[FIX] payment_paypal: correctly parse payment_date
Paypal formats the payment date in this specific format: `HH:MM:SS Mmm DD, YYYY PDT`. Source: https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/ opw-693574
This commit is contained in:
@@ -4,6 +4,9 @@ import json
|
||||
import logging
|
||||
import urlparse
|
||||
|
||||
import dateutil.parser
|
||||
import pytz
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.addons.payment.models.payment_acquirer import ValidationError
|
||||
from odoo.addons.payment_paypal.controllers.main import PaypalController
|
||||
@@ -193,7 +196,16 @@ class TxPaypal(models.Model):
|
||||
}
|
||||
if status in ['Completed', 'Processed']:
|
||||
_logger.info('Validated Paypal payment for tx %s: set as done' % (self.reference))
|
||||
res.update(state='done', date_validate=data.get('payment_date', fields.Datetime.now()))
|
||||
try:
|
||||
# dateutil and pytz don't recognize abbreviations PDT/PST
|
||||
tzinfos = {
|
||||
'PST': -8 * 3600,
|
||||
'PDT': -7 * 3600,
|
||||
}
|
||||
date_validate = dateutil.parser.parse(data.get('payment_date'), tzinfos=tzinfos).astimezone(pytz.utc)
|
||||
except:
|
||||
date_validate = fields.Datetime.now()
|
||||
res.update(state='done', date_validate=date_validate)
|
||||
return self.write(res)
|
||||
elif status in ['Pending', 'Expired']:
|
||||
_logger.info('Received notification for Paypal payment %s: set as pending' % (self.reference))
|
||||
|
||||
@@ -187,4 +187,4 @@ class PaypalForm(PaypalCommon):
|
||||
# check
|
||||
self.assertEqual(tx.state, 'done', 'paypal: wrong state after receiving a valid pending notification')
|
||||
self.assertEqual(tx.acquirer_reference, '08D73520KX778924N', 'paypal: wrong txn_id after receiving a valid pending notification')
|
||||
self.assertEqual(tx.date_validate, '2013-11-18 03:21:19', 'paypal: wrong validation date')
|
||||
self.assertEqual(tx.date_validate, '2013-11-18 11:21:19', 'paypal: wrong validation date')
|
||||
|
||||
Reference in New Issue
Block a user