diff --git a/payment_wepay_gateway/__init__.py b/payment_wepay_gateway/__init__.py new file mode 100644 index 000000000..f6d0d7f6a --- /dev/null +++ b/payment_wepay_gateway/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author:Cybrosys Technologies () +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +import models +import controllers diff --git a/payment_wepay_gateway/__openerp__.py b/payment_wepay_gateway/__openerp__.py new file mode 100644 index 000000000..eb0b87e90 --- /dev/null +++ b/payment_wepay_gateway/__openerp__.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author: Hilar AK() +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +{ + 'name': "WePay Payment Gateway", + 'version': '9.0.1.0.0', + 'summary': """Wepay Payment Gateway.""", + 'description': """Payment Acquirer: Wepay""", + 'author': 'Cybrosys Techno Solutions', + 'company': 'Cybrosys Techno Solutions', + 'website': "http://cybrosys.com/", + 'category': 'eCommerce', + 'depends': ['base', 'payment', 'website_sale'], + 'data': [ + 'views/views.xml', + 'views/templates.xml', + 'data/wepay.xml', + ], + 'images': ['static/description/banner.jpg'], + 'license': 'LGPL-3', + 'installable': True, + 'application': True +} \ No newline at end of file diff --git a/payment_wepay_gateway/controllers/__init__.py b/payment_wepay_gateway/controllers/__init__.py new file mode 100644 index 000000000..a77b4fb03 --- /dev/null +++ b/payment_wepay_gateway/controllers/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +import main \ No newline at end of file diff --git a/payment_wepay_gateway/controllers/main.py b/payment_wepay_gateway/controllers/main.py new file mode 100644 index 000000000..169097126 --- /dev/null +++ b/payment_wepay_gateway/controllers/main.py @@ -0,0 +1,117 @@ +# -*- coding: utf-8 -*- +import logging +import pprint +import requests +import werkzeug +import json + +from openerp import http, SUPERUSER_ID +from openerp.http import request +from openerp.addons.payment.models.payment_acquirer import ValidationError + +_logger = logging.getLogger(__name__) + +class WepayController(http.Controller): + + @http.route(['/wepay/checkout'], type='http', auth='none', csrf=None, website=True) + def checkout(self, **post): + """ + Function which creates the checkout iframe after clicking on PayNow Button. It requires + wepay account id, and access tocken to create the checkout iframe. + Check https://developer.wepay.com/api-calls/checkout#create for more Information. + redirect and the callback_uri must be a full URL and must not include localhost or wepay.com. + redirect_uri must be a full uri (ex http://www.example.com) if you are in production mode. + :param post: + :return: Checkout uri provided after creating checkout, response from /checkout/create + """ + _logger.info('Wepay datas %s', pprint.pformat(post)) # debug + cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env + acquirer = env['payment.acquirer'].sudo().browse(eval(post.get('acquirer'))) + currency = env['res.currency'].sudo().browse(eval(post.get('currency_id'))).name + if currency not in ['CAD', 'GBP', 'USD']: + _logger.info("Invalid parameter 'currency' expected one of: 'CAD', 'GBP', 'USD'") + return request.redirect('/shop/cart') + url = "https://stage.wepayapi.com/v2/checkout/create" if acquirer.environment == 'test'\ + else "https://wepayapi.com/v2/checkout/create" + base_url = request.env['ir.config_parameter'].get_param('web.base.url') + return_url = base_url + '/wepay/checkout/confirm' + payload = json.dumps({ + "account_id": int(acquirer.wepay_account_id), + "amount": post.get('amount') or '', + "type": "goods", #Possible values:, goods, service, donation, event, and personal + "currency": currency, + "short_description": "Payment From Odoo E-commerce", + "long_description": "Payment From Odoo E-commerce", + "email_message": { + "to_payer": "Please contact us at 555-555-555 if you need assistance.", + "to_payee": "Please note that we cover all shipping costs." + }, + "callback_uri": return_url,#'http://example.com', + "reference_id": post.get('reference'), + "auto_release": True, + "hosted_checkout": { + "redirect_uri": return_url, + "shipping_fee": 0, + "mode": "regular", + "prefill_info": { + "email": post.get('partner_email'), + "name": post.get('billing_partner_name') or post.get('partner_name'), + "address": { + "address1": post.get("billing_partner_address") or '', + "address2": post.get("billing_partner_address") or '', + "city": post.get('billing_partner_city') or '', + "region": post.get("billing_partner_state") or '', + "postal_code": post.get('billing_partner_zip') or '', + "country": env['res.country'].sudo().browse(eval(post.get("billing_partner_country_id"))).code or '' + } + } + }, + }) + headers = { + 'content-type': "application/json", + 'authorization': "Bearer %s" % acquirer.wepay_access_tocken.replace(" ", ""), + 'cache-control': "no-cache", + } + response = requests.request("POST", url, data=payload, headers=headers) + vals = json.loads(response.text) + _logger.info(pprint.pformat(vals)) + return werkzeug.utils.redirect(vals.get('hosted_checkout')['checkout_uri']) + + @http.route(['/wepay/checkout/confirm'], type='http', auth='none', csrf=None, website=True) + def checkout_confirm(self, **post): + """ + route which serves when a transaction is completed by wepay through checkout iframe, which we defines the + return uri while creating wepay checkout. ie, redirect_uri in hosted_checkout dict. + released,authorized are the successfull transactions and cancelled,falled are the error responses. + :param post: + :return: /shop/payment/validate if success else /shop + """ + cr, uid, context, env = request.cr, SUPERUSER_ID, request.context, request.env + acquirer = env['payment.acquirer'].sudo().search([('provider', '=', 'wepay')]) + url = "https://stage.wepayapi.com/v2/checkout/" if acquirer and acquirer.environment == 'test' \ + else "https://wepayapi.com/v2/checkout/" + headers = { + 'content-type': "application/json", + 'authorization': "Bearer %s" % acquirer.wepay_access_tocken.replace(" ", ""), + 'cache-control': "no-cache", + } + tx = request.website.sale_get_transaction() + tx.sudo().wepay_checkout_id = post.get('checkout_id') + response = requests.request("POST", url, data=json.dumps(post), headers=headers) + vals = json.loads(response.text) + _logger.info(pprint.pformat(vals)) + if vals.get('state') == 'authorized': + tx.state = 'done' + tx.wepay_checkout_id = vals.get('checkout_id') + tx.sale_order_id.with_context(dict(context, send_email=True)).action_confirm() + return request.redirect('/shop/payment/validate') + elif vals.get('state') in ['cancelled', 'falled']: + tx.state = 'error' + return request.redirect('/shop') + elif vals.get('state') in ['released']: + tx.state = 'pending' + tx.wepay_checkout_id = vals.get('checkout_id') + tx.sale_order_id.with_context(dict(context, send_email=True)).action_confirm() + return request.redirect('/shop/payment/validate') + + diff --git a/payment_wepay_gateway/data/wepay.xml b/payment_wepay_gateway/data/wepay.xml new file mode 100644 index 000000000..783af32dd --- /dev/null +++ b/payment_wepay_gateway/data/wepay.xml @@ -0,0 +1,18 @@ + + + + + WePay + + wepay + + + test + You will be redirected to the Wepay payment window after clicking on the payment button.

]]>
+ dummy + dummy + dummy +
+
+
diff --git a/payment_wepay_gateway/models/__init__.py b/payment_wepay_gateway/models/__init__.py new file mode 100644 index 000000000..7fd97407e --- /dev/null +++ b/payment_wepay_gateway/models/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author:Cybrosys Technologies () +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +import models diff --git a/payment_wepay_gateway/models/models.py b/payment_wepay_gateway/models/models.py new file mode 100644 index 000000000..b575b9b0b --- /dev/null +++ b/payment_wepay_gateway/models/models.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Cybrosys Technologies Pvt. Ltd. +# Copyright (C) 2017-TODAY Cybrosys Technologies(). +# Author:Cybrosys Technologies () +# you can modify it under the terms of the GNU LESSER +# GENERAL PUBLIC LICENSE (LGPL v3), Version 3. +# +# It is forbidden to publish, distribute, sublicense, or sell copies +# of the Software or modified copies of the Software. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. +# +# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE +# GENERAL PUBLIC LICENSE (LGPL v3) along with this program. +# If not, see . +# +############################################################################## + +import logging +from openerp import models, fields, _ + +_logger = logging.getLogger(__name__) + + +class Wepay(models.Model): + _inherit = 'payment.acquirer' + + def _get_providers(self, cr, uid, context=None): + providers = super(Wepay, self)._get_providers(cr, uid, context=context) + providers.append(['wepay', 'WePay']) + return providers + wepay_merchant_id = fields.Char("Client Id") + wepay_account_id = fields.Char("Account Id") + wepay_access_tocken = fields.Char("Access Token") + + +class WepayTransaction(models.Model): + _inherit = "payment.transaction" + wepay_checkout_id = fields.Char("Wepay Checkout Id") + acquirer_name = fields.Selection(related='acquirer_id.provider') \ No newline at end of file diff --git a/payment_wepay_gateway/readme.md b/payment_wepay_gateway/readme.md new file mode 100644 index 000000000..261e2ca0e --- /dev/null +++ b/payment_wepay_gateway/readme.md @@ -0,0 +1,45 @@ +# Wepay Payment Gateway + +Wepay Payment Acquirer act as a new payment method in odoo e-commerce and easy checkout functionality with two steps. + + - We have two modes test & production + - Test Url - https://stage.wepay.com/ + - Production mode - https://www.wepay.com/ + - Follow here to create test account https://stage.wepay.com/register/ + - Follow here to create Production account https://www.wepay.com/register/ + + - expected one of currencies 'CAD', 'GBP', 'USD' + +### Depends +Ecommerce, Website, Payment modules in odoo + +### Tech +* [Python] - Models,Controllers +* [XML] - Odoo website templates, views + +### Installation +- www.odoo.com/documentation/9.0/setup/install.html +- Install our custom addon, which also installs its depends [website, website_sale, payment] + +### Usage +> Provide Wepay test or active account credentials. +> Account id, access_tocken, client id will be get after creating a client account on wepay. +> Follow https://support.wepay.com/hc/en-us/articles/203609673-How-do-I-set-up-my-WePay-account- for account creation. +> Wepay Support https://support.wepay.com/hc/en-us/articles/203609503-WePay-FAQ +> Publish wepay acquirer for odoo e-commerce. +> redirect and the callback_uri must be a full URL and must not include localhost or wepay.com. + +### References +https://developer.wepay.com/ +https://www.wepay.com/developer +https://www.wepay.com/developer/register +https://stage-go.wepay.com/ +https://go.wepay.com/ + +License +---- +GNU LESSER GENERAL PUBLIC LICENSE, Version 3 (LGPLv3) +(http://www.gnu.org/licenses/agpl.html) + + + diff --git a/payment_wepay_gateway/security/ir.model.access.csv b/payment_wepay_gateway/security/ir.model.access.csv new file mode 100644 index 000000000..158502632 --- /dev/null +++ b/payment_wepay_gateway/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_payment_wepay_gateway,payment_wepay_gateway.payment_wepay,model_payment_wepay_gateway,,1,0,0,0 \ No newline at end of file diff --git a/payment_wepay_gateway/static/description/apidashboard.png b/payment_wepay_gateway/static/description/apidashboard.png new file mode 100644 index 000000000..202934cc4 Binary files /dev/null and b/payment_wepay_gateway/static/description/apidashboard.png differ diff --git a/payment_wepay_gateway/static/description/banner.jpg b/payment_wepay_gateway/static/description/banner.jpg new file mode 100644 index 000000000..8a581e88f Binary files /dev/null and b/payment_wepay_gateway/static/description/banner.jpg differ diff --git a/payment_wepay_gateway/static/description/checkoutconfirm.png b/payment_wepay_gateway/static/description/checkoutconfirm.png new file mode 100644 index 000000000..21ca6dbbf Binary files /dev/null and b/payment_wepay_gateway/static/description/checkoutconfirm.png differ diff --git a/payment_wepay_gateway/static/description/checkoutiframe.png b/payment_wepay_gateway/static/description/checkoutiframe.png new file mode 100644 index 000000000..2ecb10a6f Binary files /dev/null and b/payment_wepay_gateway/static/description/checkoutiframe.png differ diff --git a/payment_wepay_gateway/static/description/cybro_logo.png b/payment_wepay_gateway/static/description/cybro_logo.png new file mode 100644 index 000000000..bb309114c Binary files /dev/null and b/payment_wepay_gateway/static/description/cybro_logo.png differ diff --git a/payment_wepay_gateway/static/description/icon.png b/payment_wepay_gateway/static/description/icon.png new file mode 100644 index 000000000..6686b7ad9 Binary files /dev/null and b/payment_wepay_gateway/static/description/icon.png differ diff --git a/payment_wepay_gateway/static/description/index.html b/payment_wepay_gateway/static/description/index.html new file mode 100644 index 000000000..e7e79de05 --- /dev/null +++ b/payment_wepay_gateway/static/description/index.html @@ -0,0 +1,159 @@ +
+

Wepay Payment Gateway

+

Author : Cybrosys Techno Solutions , www.cybrosys.com

+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+

Need Any Help?

+ +
diff --git a/payment_wepay_gateway/static/description/paymentshop.png b/payment_wepay_gateway/static/description/paymentshop.png new file mode 100644 index 000000000..b1ec021bd Binary files /dev/null and b/payment_wepay_gateway/static/description/paymentshop.png differ diff --git a/payment_wepay_gateway/static/description/shopconfirm.png b/payment_wepay_gateway/static/description/shopconfirm.png new file mode 100644 index 000000000..86097fd38 Binary files /dev/null and b/payment_wepay_gateway/static/description/shopconfirm.png differ diff --git a/payment_wepay_gateway/static/description/transaction.png b/payment_wepay_gateway/static/description/transaction.png new file mode 100644 index 000000000..5d517a24e Binary files /dev/null and b/payment_wepay_gateway/static/description/transaction.png differ diff --git a/payment_wepay_gateway/static/description/wepaybackend.png b/payment_wepay_gateway/static/description/wepaybackend.png new file mode 100644 index 000000000..822b33022 Binary files /dev/null and b/payment_wepay_gateway/static/description/wepaybackend.png differ diff --git a/payment_wepay_gateway/static/description/wepaytransaction.png b/payment_wepay_gateway/static/description/wepaytransaction.png new file mode 100644 index 000000000..571aa4338 Binary files /dev/null and b/payment_wepay_gateway/static/description/wepaytransaction.png differ diff --git a/payment_wepay_gateway/static/src/img/wepay_icon.png b/payment_wepay_gateway/static/src/img/wepay_icon.png new file mode 100644 index 000000000..59cfaec08 Binary files /dev/null and b/payment_wepay_gateway/static/src/img/wepay_icon.png differ diff --git a/payment_wepay_gateway/views/templates.xml b/payment_wepay_gateway/views/templates.xml new file mode 100644 index 000000000..25ebefcf1 --- /dev/null +++ b/payment_wepay_gateway/views/templates.xml @@ -0,0 +1,29 @@ + + + + + \ No newline at end of file diff --git a/payment_wepay_gateway/views/views.xml b/payment_wepay_gateway/views/views.xml new file mode 100644 index 000000000..0fdedfa63 --- /dev/null +++ b/payment_wepay_gateway/views/views.xml @@ -0,0 +1,37 @@ + + + + Wepay Acquirer Form + payment.acquirer + + + + + + + + How to configure your Wepay account? + For more support + + + + + + + Payment Transaction View Extend + payment.transaction + + + + + + + + + + + + \ No newline at end of file