13 Commits
14 changed files with 74 additions and 46 deletions
+10 -2
View File
@@ -3,6 +3,7 @@
## This is the module to connect Odoo 9.0 and BTCPay ## This is the module to connect Odoo 9.0 and BTCPay
This module allow you to create an easily way to accept cryptocurrencies. This module allow you to create an easily way to accept cryptocurrencies.
![BTCPay](/payment_btcpay/static/description/Btcpay_com.png)
## Configure Payment Acquirer ## Configure Payment Acquirer
* Install BTCPay Module -> Website -> eCommerce -> Payment Acquirers -> BTCPay * Install BTCPay Module -> Website -> eCommerce -> Payment Acquirers -> BTCPay
@@ -15,7 +16,14 @@ This module allow you to create an easily way to accept cryptocurrencies.
* If you have a Private Key you can write here otherwise system will get when you safe the Payment Acquirer * If you have a Private Key you can write here otherwise system will get when you safe the Payment Acquirer
* Remember to Publish On Website * Remember to Publish On Website
![Payment Acquirer](/static/description/BTCPayPaymentAcquirer.png) ![Payment Acquirer](/payment_btcpay/static/description/BTCPayPaymentAcquirer.png)
## How it looks like?
In payment webpage where payment methods appear, you will find new payment method called BTCPay. If you click on it you will be redirect to the server that you indicate in location field.
![Payment Acquirer](/payment_btcpay/static/description/BTCPayLooksLike.png)
## Transaction BTCPay Details ## Transaction BTCPay Details
In transaction object, you will find more technical information about this method of payment: In transaction object, you will find more technical information about this method of payment:
@@ -24,4 +32,4 @@ In transaction object, you will find more technical information about this metho
* Transaction Status: That indicates state of transaction * Transaction Status: That indicates state of transaction
* Buyer Mail Notification: Indicates if mail has been sent or if not (it will be in blank) * Buyer Mail Notification: Indicates if mail has been sent or if not (it will be in blank)
![Transaction Btcpay Details](/static/description/BtcpayTxDetails.png) ![Transaction Btcpay Details](/payment_btcpay/static/description/BtcpayTxDetails.png)
+34 -26
View File
@@ -45,41 +45,48 @@ _logger = logging.getLogger(__name__)
class BtcpayController(http.Controller): class BtcpayController(http.Controller):
_notify_url = '/payment/btcpay/ipn' _notify_url = '/payment/btcpay/ipn'
@http.route('/payment/btcpay/ipn', type='json', auth='public', methods=['POST'], csrf=False)
@http.route('/payment/btcpay/ipn', type='json', auth='none')
def btcpay_ipn(self, **post): def btcpay_ipn(self, **post):
""" BTCPay IPN. """ """ BTCPay IPN. """
_logger.info('BTCPAY IPN RECEIVED...')
cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env
acquirer = request.env['payment.acquirer'].search([('provider', '=', 'btcpay')]) acquirer = env['payment.acquirer'].search([('provider', '=', 'btcpay')])
try:
#for k in request.jsonrequest['data']:
# _logger.info('\t%s => %s', k, request.jsonrequest['data'][k])
invoiceId = request.jsonrequest['data']['id']
invoiceStatus = request.jsonrequest['data']['status']
orderId = request.jsonrequest['data']['orderId']
_logger.info('Invoice ID %s => %s (Order ID %s)', invoiceId, invoiceStatus, orderId)
#_logger.info('REQUEST JSONREQUEST %s',pprint.pformat(request.jsonrequest)) #client = BTCPayClient(host=acquirer.location, pem=acquirer.privateKey, tokens=acquirer.token)
invoiceId = request.jsonrequest['data']['id'] #self.invoice = client.get_invoice(invoiceId)
#_logger.info('SELF INVOICE IPN %s',self.invoice)
client = BTCPayClient(host=acquirer.location, pem=acquirer.privateKey, tokens=acquirer.token) if invoiceId and orderId:
tx_ids = request.registry['payment.transaction'].search(cr, uid, [('reference', '=', orderId)], context=context)
if tx_ids:
tx = request.registry['payment.transaction'].browse(cr, uid, tx_ids[0], context=context)
self.invoice = client.get_invoice(invoiceId) tx.btcpay_status = invoiceStatus
#_logger.info('SELF INVOICE IPN %s',pprint.pformat(self.invoice)) if invoiceStatus in ['confirmed']:
tx.state = 'done'
tx.sale_order_id.state = 'sale'
if not tx.btcpay_buyerMailNotification and acquirer.buyerNotification:
tx.sale_order_id.force_quotation_send()
tx.btcpay_buyerMailNotification = "Send"
tx.sale_order_id.order_line._action_procurement_create()
elif invoiceStatus in ['paid']:
tx.state = 'pending'
tx.btcpay_invoiceId = invoiceId
tx.btcpay_txid = request.jsonrequest['data']['url']
tx = None except Exception as e:
if self.invoice['orderId']: _logger.error(e)
tx_ids = request.registry['payment.transaction'].search(cr, uid, [('reference', '=', self.invoice['orderId'])], context=context)
if tx_ids:
tx = request.registry['payment.transaction'].browse(cr, uid, tx_ids[0], context=context)
tx.btcpay_status = self.invoice['status']
if self.invoice['status'] in ['confirmed']:
tx.state = 'done'
tx.sale_order_id.state = 'sale'
if not tx.btcpay_buyerMailNotification and acquirer.buyerNotification:
tx.sale_order_id.force_quotation_send()
tx.btcpay_buyerMailNotification = "Send"
tx.sale_order_id.order_line._action_procurement_create()
elif self.invoice['status'] in ['paid']:
tx.state = 'pending'
tx.btcpay_invoiceId =self.invoice['id']
tx.btcpay_txid =((((self.invoice['cryptoInfo'])[0])['payments'])[0])['id']
return '' return ''
@http.route(['/btcpay/checkout'], type='http', auth='none', csrf=None, website=True) @http.route(['/btcpay/checkout'], type='http', auth='none', csrf=None, website=True)
def checkout(self, **post): def checkout(self, **post):
cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env
@@ -108,3 +115,4 @@ class BtcpayController(http.Controller):
invoiceId = dict(acquirer.invoice)['id'] invoiceId = dict(acquirer.invoice)['id']
self.invoice = client.get_invoice(invoiceId) self.invoice = client.get_invoice(invoiceId)
return werkzeug.utils.redirect(self.invoice['url']) return werkzeug.utils.redirect(self.invoice['url'])
@@ -1,3 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<!--****************************************************************************** <!--******************************************************************************
# PAYMENT BTCPAY FOR ODOO # PAYMENT BTCPAY FOR ODOO
# #
@@ -18,19 +20,17 @@
# For a full copy of the GNU General Public License see the LICENSE.txt file. # For a full copy of the GNU General Public License see the LICENSE.txt file.
# #
#******************************************************************************--> #******************************************************************************-->
<?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data noupdate="1"> <data noupdate="1">
<record id="payment_acquirer_btcpay" model="payment.acquirer"> <record id="payment_acquirer_btcpay" model="payment.acquirer">
<field name="name">Btcpay</field> <field name="name">BTCPay</field>
<field name="image" type="base64" file="payment_btcpay/static/description/icon.png"/> <field name="image" type="base64" file="payment_btcpay/static/description/icon.png"/>
<field name="provider">btcpay</field> <field name="provider">BTCPay</field>
<field name="company_id" ref="base.main_company"/> <field name="company_id" ref="base.main_company"/>
<field name="view_template_id" ref="btcpay_acquirer_form"/> <field name="view_template_id" ref="btcpay_acquirer_form"/>
<field name="environment">test</field> <field name="environment">test</field>
<field name="pre_msg"><![CDATA[ <field name="pre_msg"><![CDATA[
<p>You will be redirected to BTCPay website after clicking on the payment button.</p>]]></field> <p><br>You will be redirected to BTCPay website after clicking on the payment button.</p>]]></field>
</record> </record>
</data> </data>
</openerp> </openerp>
+4 -3
View File
@@ -56,20 +56,21 @@ class AcquirerBtcPay(models.Model):
def create(self, cr, uid, values, context=None): def create(self, cr, uid, values, context=None):
if not values.get('privateKey'): if values.get('provider') == 'btcpay' and not values.get('privateKey'):
values['privateKey'] = bku.generate_privkey() values['privateKey'] = bku.generate_privkey()
return super(AcquirerBtcPay, self).create(cr, uid, values, context=context) return super(AcquirerBtcPay, self).create(cr, uid, values, context=context)
@api.onchange('pairingCode') @api.onchange('pairingCode')
def _onchange_pairingCode(self): def _onchange_pairingCode(self):
if not self.token: if not self.token and self.provider == 'btcpay':
client = BTCPayClient(host=self.location, pem=self.privateKey) client = BTCPayClient(host=self.location, pem=self.privateKey)
token = client.pair_client(self.pairingCode) token = client.pair_client(self.pairingCode)
self.token = token.get(self.facade) self.token = token.get(self.facade)
@api.onchange('token') @api.onchange('token')
def _onchange_token(self): def _onchange_token(self):
self.pairingCode = '' if self.provider == 'btcpay':
self.pairingCode = ''
class BtcPayTransaction(models.Model): class BtcPayTransaction(models.Model):
Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

+1
View File
@@ -0,0 +1 @@
Bitcoin-Lightning-Network.png
Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

+1 -1
View File
@@ -58,4 +58,4 @@ fetched_invoice = client.get_invoice(new_invoice['id'])
print("FETCHED INVOICE: ", new_invoice['id']) print("FETCHED INVOICE: ", new_invoice['id'])
curl --no-keepalive --raw --show-error --verbose --connect-timeout 10 --insecure --max-redirs 1 -H "Content-Type: application/json" -d '{"data": "{"id":"P38S4ewSvvLoRrBSoEiMTz"}"}" http://odoo-dev.zynthian.org/payment/btcpay/ipn curl --no-keepalive --raw --show-error --verbose --connect-timeout 10 --insecure --max-redirs 1 -H "Content-Type: application/json" -d '{"data": "{"id":"8vQMp1C6gB1DxUyJB9gcBp"}"}" http://odoo-dev.zynthian.org/payment/btcpay/ipn
+12
View File
@@ -0,0 +1,12 @@
import requests
import json
url = 'https://odoo-dev.zynthian.org/payment/btcpay/ipn'
headers = {'Content-Type': 'application/json'}
data = {
"data": {
"id":"8vQMp1C6gB1DxUyJB9gcBp",
}
}
data_json = json.dumps(data)
r = requests.post(url=url, data=data_json, headers=headers)
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--****************************************************************************** <!--******************************************************************************
# PAYMENT BTCPAY FOR ODOO # PAYMENT BTCPAY FOR ODOO
# #
@@ -19,8 +20,6 @@
# #
#******************************************************************************--> #******************************************************************************-->
<?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<record id="acquirer_form_btcpay" model="ir.ui.view"> <record id="acquirer_form_btcpay" model="ir.ui.view">
+1 -1
View File
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--****************************************************************************** <!--******************************************************************************
# PAYMENT BTCPAY FOR ODOO # PAYMENT BTCPAY FOR ODOO
# #
@@ -19,7 +20,6 @@
# #
#******************************************************************************--> #******************************************************************************-->
<?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<!--BtcPay Top Menu--> <!--BtcPay Top Menu-->
@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<!--****************************************************************************** <!--******************************************************************************
# PAYMENT BTCPAY FOR ODOO # PAYMENT BTCPAY FOR ODOO
# #
@@ -19,8 +20,6 @@
# #
#******************************************************************************--> #******************************************************************************-->
<?xml version="1.0" encoding="utf-8"?>
<openerp> <openerp>
<data> <data>
<template id="btcpay_acquirer_form" name="Btcpay Payment Button"> <template id="btcpay_acquirer_form" name="Btcpay Payment Button">
@@ -45,3 +44,4 @@
</template> </template>
</data> </data>
</openerp> </openerp>