Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac2194498a | ||
|
|
2e832d5b18 | ||
|
|
bad3ea017b | ||
|
|
80ce33f40d | ||
|
|
0c251a6790 | ||
|
|
25aecac922 | ||
|
|
b2820f1cb2 | ||
|
|
01d2a36d37 | ||
|
|
363c4169dc | ||
|
|
e980bad67e | ||
|
|
0aa10bf49c | ||
|
|
ef6f02da2a | ||
|
|
8844df3cb6 |
@@ -3,6 +3,7 @@
|
||||
|
||||
## This is the module to connect Odoo 9.0 and BTCPay
|
||||
This module allow you to create an easily way to accept cryptocurrencies.
|
||||

|
||||
|
||||
## Configure Payment Acquirer
|
||||
* 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
|
||||
* Remember to Publish On Website
|
||||
|
||||

|
||||

|
||||
|
||||
## 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.
|
||||
|
||||

|
||||
|
||||
|
||||
## Transaction BTCPay Details
|
||||
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
|
||||
* Buyer Mail Notification: Indicates if mail has been sent or if not (it will be in blank)
|
||||
|
||||

|
||||

|
||||
|
||||
@@ -45,41 +45,48 @@ _logger = logging.getLogger(__name__)
|
||||
class BtcpayController(http.Controller):
|
||||
_notify_url = '/payment/btcpay/ipn'
|
||||
|
||||
|
||||
@http.route('/payment/btcpay/ipn', type='json', auth='none')
|
||||
@http.route('/payment/btcpay/ipn', type='json', auth='public', methods=['POST'], csrf=False)
|
||||
def btcpay_ipn(self, **post):
|
||||
""" BTCPay IPN. """
|
||||
|
||||
_logger.info('BTCPAY IPN RECEIVED...')
|
||||
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))
|
||||
invoiceId = request.jsonrequest['data']['id']
|
||||
|
||||
client = BTCPayClient(host=acquirer.location, pem=acquirer.privateKey, tokens=acquirer.token)
|
||||
|
||||
self.invoice = client.get_invoice(invoiceId)
|
||||
#_logger.info('SELF INVOICE IPN %s',pprint.pformat(self.invoice))
|
||||
|
||||
tx = None
|
||||
if self.invoice['orderId']:
|
||||
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)
|
||||
#client = BTCPayClient(host=acquirer.location, pem=acquirer.privateKey, tokens=acquirer.token)
|
||||
#self.invoice = client.get_invoice(invoiceId)
|
||||
#_logger.info('SELF INVOICE IPN %s',self.invoice)
|
||||
|
||||
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)
|
||||
|
||||
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']
|
||||
tx.btcpay_status = invoiceStatus
|
||||
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']
|
||||
|
||||
except Exception as e:
|
||||
_logger.error(e)
|
||||
return ''
|
||||
|
||||
|
||||
@http.route(['/btcpay/checkout'], type='http', auth='none', csrf=None, website=True)
|
||||
def checkout(self, **post):
|
||||
cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env
|
||||
@@ -107,4 +114,5 @@ class BtcpayController(http.Controller):
|
||||
"notify": False}})
|
||||
invoiceId = dict(acquirer.invoice)['id']
|
||||
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
|
||||
#
|
||||
@@ -18,19 +20,17 @@
|
||||
# For a full copy of the GNU General Public License see the LICENSE.txt file.
|
||||
#
|
||||
#******************************************************************************-->
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
<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="provider">btcpay</field>
|
||||
<field name="provider">BTCPay</field>
|
||||
<field name="company_id" ref="base.main_company"/>
|
||||
<field name="view_template_id" ref="btcpay_acquirer_form"/>
|
||||
<field name="environment">test</field>
|
||||
<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>
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
@@ -56,20 +56,21 @@ class AcquirerBtcPay(models.Model):
|
||||
|
||||
|
||||
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()
|
||||
return super(AcquirerBtcPay, self).create(cr, uid, values, context=context)
|
||||
|
||||
@api.onchange('pairingCode')
|
||||
def _onchange_pairingCode(self):
|
||||
if not self.token:
|
||||
if not self.token and self.provider == 'btcpay':
|
||||
client = BTCPayClient(host=self.location, pem=self.privateKey)
|
||||
token = client.pair_client(self.pairingCode)
|
||||
self.token = token.get(self.facade)
|
||||
|
||||
@api.onchange('token')
|
||||
def _onchange_token(self):
|
||||
self.pairingCode = ''
|
||||
if self.provider == 'btcpay':
|
||||
self.pairingCode = ''
|
||||
|
||||
|
||||
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 |
@@ -0,0 +1 @@
|
||||
Bitcoin-Lightning-Network.png
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 4.7 KiB |
@@ -58,4 +58,4 @@ fetched_invoice = client.get_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
|
||||
@@ -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
|
||||
#
|
||||
@@ -19,8 +20,6 @@
|
||||
#
|
||||
#******************************************************************************-->
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="acquirer_form_btcpay" model="ir.ui.view">
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--******************************************************************************
|
||||
# PAYMENT BTCPAY FOR ODOO
|
||||
#
|
||||
@@ -19,7 +20,6 @@
|
||||
#
|
||||
#******************************************************************************-->
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<!--BtcPay Top Menu-->
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--******************************************************************************
|
||||
# PAYMENT BTCPAY FOR ODOO
|
||||
#
|
||||
@@ -19,8 +20,6 @@
|
||||
#
|
||||
#******************************************************************************-->
|
||||
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<template id="btcpay_acquirer_form" name="Btcpay Payment Button">
|
||||
@@ -44,4 +43,5 @@
|
||||
</form>
|
||||
</template>
|
||||
</data>
|
||||
</openerp>
|
||||
</openerp>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user