Remove customizable return url and redirect the user to order confirmation / payment status page as it would be expected.
This commit is contained in:
@@ -42,6 +42,7 @@ _logger = logging.getLogger(__name__)
|
|||||||
class BTCPayController(http.Controller):
|
class BTCPayController(http.Controller):
|
||||||
_checkout_url = '/btcpay/checkout'
|
_checkout_url = '/btcpay/checkout'
|
||||||
_notify_url = '/payment/btcpay/ipn'
|
_notify_url = '/payment/btcpay/ipn'
|
||||||
|
_return_url = '/payment/btcpay/return'
|
||||||
|
|
||||||
@http.route(_checkout_url, type='http', auth='public', csrf=False, website=True)
|
@http.route(_checkout_url, type='http', auth='public', csrf=False, website=True)
|
||||||
def checkout(self, **data):
|
def checkout(self, **data):
|
||||||
@@ -49,15 +50,17 @@ class BTCPayController(http.Controller):
|
|||||||
_logger.info("CHECKOUT: notification received from BTCPay with data:\n%s", pprint.pformat(data))
|
_logger.info("CHECKOUT: notification received from BTCPay with data:\n%s", pprint.pformat(data))
|
||||||
tx_sudo = request.env['payment.transaction'].sudo()._get_tx_from_notification_data('btcpay', data)
|
tx_sudo = request.env['payment.transaction'].sudo()._get_tx_from_notification_data('btcpay', data)
|
||||||
provider = tx_sudo.provider_id
|
provider = tx_sudo.provider_id
|
||||||
notificationURL = str(data.get('notify_url')).replace("http://", "https://")
|
notification_url = str(data.get('notify_url')).replace("http://", "https://")
|
||||||
|
base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url')
|
||||||
|
redirect_url = urls.url_join(base_url, self._return_url)
|
||||||
client = BTCPayClient(host=provider.btcpay_location, pem=provider.btcpay_privateKey, tokens={provider.btcpay_facade: provider.btcpay_token})
|
client = BTCPayClient(host=provider.btcpay_location, pem=provider.btcpay_privateKey, tokens={provider.btcpay_facade: provider.btcpay_token})
|
||||||
invoice = client.create_invoice(
|
invoice = client.create_invoice(
|
||||||
{"price": data.get('amount'),
|
{"price": data.get('amount'),
|
||||||
"currency": data.get('currency_id'),
|
"currency": data.get('currency_id'),
|
||||||
"orderId": data.get('reference'),
|
"orderId": data.get('reference'),
|
||||||
"token": provider.btcpay_token,
|
"token": provider.btcpay_token,
|
||||||
"redirectURL": provider.btcpay_confirmationURL,
|
"redirectURL": redirect_url,
|
||||||
"notificationURL": notificationURL,
|
"notificationURL": notification_url,
|
||||||
"extendedNotifications": True,
|
"extendedNotifications": True,
|
||||||
"buyer": {"email": data.get('email'),
|
"buyer": {"email": data.get('email'),
|
||||||
"name": data.get('name'),
|
"name": data.get('name'),
|
||||||
@@ -66,7 +69,7 @@ class BTCPayController(http.Controller):
|
|||||||
"postalCode": data.get('zip'),
|
"postalCode": data.get('zip'),
|
||||||
"country": data.get('country'),
|
"country": data.get('country'),
|
||||||
"notify": False}})
|
"notify": False}})
|
||||||
_logger.info('Invoice %s \n NOTIFY URL: %s', invoice, notificationURL)
|
_logger.info('Invoice %s \n NOTIFY URL: %s', invoice, notification_url)
|
||||||
return werkzeug.utils.redirect(invoice['url'])
|
return werkzeug.utils.redirect(invoice['url'])
|
||||||
|
|
||||||
@http.route(_notify_url, type='json', auth='public', csrf=False)
|
@http.route(_notify_url, type='json', auth='public', csrf=False)
|
||||||
@@ -97,3 +100,13 @@ class BTCPayController(http.Controller):
|
|||||||
except ValidationError: # Acknowledge the notification to avoid getting spammed
|
except ValidationError: # Acknowledge the notification to avoid getting spammed
|
||||||
_logger.exception("Unable to handle the notification data; skipping to acknowledge")
|
_logger.exception("Unable to handle the notification data; skipping to acknowledge")
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
|
@http.route(_return_url, type='http', auth="public", methods=['GET'], crsf=False, save_session=False)
|
||||||
|
def btcpay_return_from_redirect(self, **data):
|
||||||
|
""" BTCPay return
|
||||||
|
|
||||||
|
We could process and check the invoice status here but there is no need to as the status get's updated via
|
||||||
|
IPN anyway, so just show the user the order confirmation / payment status page.
|
||||||
|
"""
|
||||||
|
_logger.info("BTCPay: user returned to shop after payment")
|
||||||
|
return request.redirect('/payment/status')
|
||||||
@@ -14,7 +14,6 @@ class PaymentProvider(models.Model):
|
|||||||
selection_add=[('btcpay', "BTCPay")], ondelete={'btcpay': 'set default'})
|
selection_add=[('btcpay', "BTCPay")], ondelete={'btcpay': 'set default'})
|
||||||
|
|
||||||
btcpay_location = fields.Char(string='BTCPay Server URL', size=64, help='URL where your BTCPay Server instance is reachable (where you log into your BTCPay Server).', default='https://testnet.demo.btcpayserver.org')
|
btcpay_location = fields.Char(string='BTCPay Server URL', size=64, help='URL where your BTCPay Server instance is reachable (where you log into your BTCPay Server).', default='https://testnet.demo.btcpayserver.org')
|
||||||
btcpay_confirmationURL = fields.Char(string='Confirmation URL', help='Confirmation URL to return after BTCPay payment', default='http://yourdomain/shop/confirmation')
|
|
||||||
btcpay_pairingCode = fields.Char(string='Pairing Code', help='Create paring Code in your BTCPay server and put here')
|
btcpay_pairingCode = fields.Char(string='Pairing Code', help='Create paring Code in your BTCPay server and put here')
|
||||||
|
|
||||||
btcpay_token = fields.Char(string='Token', help='Access Token to BTCPay. Leave empty, will be autogenerated during pairing.')
|
btcpay_token = fields.Char(string='Token', help='Access Token to BTCPay. Leave empty, will be autogenerated during pairing.')
|
||||||
|
|||||||
@@ -9,7 +9,6 @@
|
|||||||
<group name="provider_credentials" position='inside'>
|
<group name="provider_credentials" position='inside'>
|
||||||
<group invisible="code != 'btcpay'">
|
<group invisible="code != 'btcpay'">
|
||||||
<field name="btcpay_location"/>
|
<field name="btcpay_location"/>
|
||||||
<field name="btcpay_confirmationURL"/>
|
|
||||||
<field name="btcpay_pairingCode"/>
|
<field name="btcpay_pairingCode"/>
|
||||||
</group>
|
</group>
|
||||||
<group invisible="code != 'btcpay'">
|
<group invisible="code != 'btcpay'">
|
||||||
|
|||||||
Reference in New Issue
Block a user