[FIX] payment_razorpay: resolve error The phone number is invalid

Before this commit:
In POS online payment the usually the user is either the
logged in user/public user which ends up raising error
`The phone number is invalid` even when the customer is selected

After this commit:
Razorpay doesn't raise the error instead now we don't create
customer when it is not a tokenize request

task-3786679

closes odoo/odoo#157533

Signed-off-by: Harsh Modi (hamo) <hamo@odoo.com>
This commit is contained in:
Harsh Modi
2024-03-22 13:02:01 +00:00
parent c02eb17aae
commit 4ff3638450
2 changed files with 9 additions and 4 deletions
@@ -34,7 +34,8 @@ class PaymentTransaction(models.Model):
if self.provider_code != 'razorpay':
return res
customer_id = self._razorpay_create_customer()['id']
customer_is_required = self.tokenize or self.operation in ('online_token', 'offline')
customer_id = customer_is_required and self._razorpay_create_customer()['id']
order_id = self._razorpay_create_order(customer_id)['id']
return {
'razorpay_key_id': self.provider_id.razorpay_key_id,
@@ -121,7 +122,8 @@ class PaymentTransaction(models.Model):
'method': pm_code,
}
if self.operation in ['online_direct', 'validation']:
payload['customer_id'] = customer_id # Required for only non-subsequent payments.
if customer_id:
payload['customer_id'] = customer_id # Required for only non-subsequent payments.
if self.tokenize:
payload['token'] = {
'max_amount': payment_utils.to_minor_currency_units(
@@ -58,10 +58,9 @@ paymentForm.include({
* @return {object}
*/
_prepareRazorpayOptions(processingValues) {
return Object.assign({}, processingValues, {
const vals = Object.assign({}, processingValues, {
'key': processingValues['razorpay_key_id'],
'order_id': processingValues['razorpay_order_id'],
'customer_id': processingValues['razorpay_customer_id'],
'description': processingValues['reference'],
'recurring': processingValues['is_tokenize_request'] ? '1': '0',
'handler': response => {
@@ -79,6 +78,10 @@ paymentForm.include({
}
},
});
if (processingValues['razorpay_customer_id']) {
vals['customer_id'] = processingValues['razorpay_customer_id'];
}
return vals;
},
});