Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
vandekul committed Sep 24, 2021
1 parent a03a3ad commit 9e55649
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 19 deletions.
6 changes: 3 additions & 3 deletions payment_stripe/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
'price':'100',
'application': True,
'depends': ['base', 'payment'],
'name': 'Paypal as a Friend Payment Acquirer',
'name': 'Stripe Payment Acquirer',
'author':'mumaker',
'category': 'Accounting',
'summary': 'Payment Acquirer: Paypal as a Friend Implementation',
'summary': 'Payment Acquirer: Stripe Implementation',
'version': '1.0',
'description': """Paypal as a Friend Payment Acquirer
'description': """Stripe Payment Acquirer
201910
It includes changing status in transaction payment when quotation is confirm/cancell/draft manually.
This changing will afect wire transfer and paypal as a friend payment acquirer and they need to select
Expand Down
6 changes: 4 additions & 2 deletions payment_stripe/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ class StripeController(http.Controller):
def stripe_s2s_create_json(self, **kwargs):
acquirer_id = int(kwargs.get('acquirer_id'))
acquirer = request.env['payment.acquirer'].browse(acquirer_id)
_logger.info('STRIPE_CONTROLLER: stripe_s2s_create_json')
return acquirer.s2s_process(kwargs)

@http.route(['/payment/stripe/s2s/create'], type='http', auth='public')
def stripe_s2s_create(self, **post):
acquirer_id = int(post.get('acquirer_id'))
acquirer = request.env['payment.acquirer'].browse(acquirer_id)
acquirer.s2s_process(post)
return werkzeug.utils.redirect(post.get('return_url', '/'))
_logger.info('STRIPE_CONTROLLER: stripe_s2s_create %s', request.env['ir.config_parameter'].get_param('web.base.url'))
return werkzeug.utils.redirect(post.get('return_url', request.env['ir.config_parameter'].get_param('web.base.url')+'/confirmation'))

@http.route(['/payment/stripe/create_charge'], type='json', auth='public')
def stripe_create_charge(self, **post):
Expand All @@ -39,4 +41,4 @@ def stripe_create_charge(self, **post):
_logger.info('Stripe: entering form_feedback with post data %s', pprint.pformat(response))
if response:
request.env['payment.transaction'].sudo().with_context(lang=None).form_feedback(response, 'stripe')
return post.pop('return_url', '/')
return post.pop('return_url', request.env['ir.config_parameter'].get_param('web.base.url')+'/confirmation')
9 changes: 3 additions & 6 deletions payment_stripe/models/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,10 @@ def stripe_form_generate_values(self, cr, uid, id, values, context=None):
'name': values.get('partner_name'),
'phone': values.get('partner_phone'),
}
temp_stripe_tx_values['returndata'] = stripe_tx_values.pop('return_url', '')
temp_stripe_tx_values['returndata'] = stripe_tx_values.pop('return_url', '/')
stripe_tx_values.update(temp_stripe_tx_values)
return stripe_tx_values

def _get_stripe_api_url(self, cr, uid, environment, context=None):
return 'api.stripe.com/v1'

def stripe_s2s_form_process(self, cr, uid, data, context=None):
values = {
'cc_number': data.get('cc_number'),
Expand Down Expand Up @@ -116,7 +113,7 @@ class PaymentTransactionStripe(models.Model):
_inherit = 'payment.transaction'

def _create_stripe_charge(self, acquirer_ref=None, tokenid=None, email=None):
api_url_charge = 'https://%s/charges' % (self.acquirer_id._get_stripe_api_url())
api_url_charge = 'https://api.stripe.com/v1/charges'
charge_params = {
'amount': int(self.amount if self.currency_id.name in INT_CURRENCIES else float_round(self.amount * 100, 2)),
'currency': self.currency_id.name,
Expand Down Expand Up @@ -149,7 +146,7 @@ def stripe_s2s_do_transaction(self, cr, uid, id, context=None, **kwargs):
def _stripe_form_get_tx_from_data(self, cr, uid, data, context=None):
""" Given a data dict coming from stripe, verify it and find the related
transaction record. """
reference = data.get('reference')
reference = data.get('metadata', {}).get('reference')
if not reference:
error_msg = _(
'Stripe: invalid reply received from provider, missing reference. Additional message: %s'
Expand Down
10 changes: 5 additions & 5 deletions payment_stripe/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ <h2 class="oe_slogan">Stripe Gateway</h2>
<h3 class="oe_slogan">This is the module to connect Odoo 9.0 and Stripe</h3>
<div class="oe_span6">
<div class="oe_bg_img">
<img src="Bitpay_com.png" class="oe_picture oe_screenshot">
<img src="icon.png" class="oe_picture oe_screenshot">
</div>
</div>
<div class="oe_span6">
Expand All @@ -28,7 +28,7 @@ <h2 class="oe_slogan">Pre-Configure in your Server</h2>
</div>
<div class="oe_span6">
<div class="oe_bg_img">
<img src="Terminal.png" class="oe_picture oe_screenshot">
<img src="icon.png" class="oe_picture oe_screenshot">
</div>
</div>
</div>
Expand All @@ -39,7 +39,7 @@ <h2 class="oe_slogan">Pre-Configure in your Server</h2>
<h2 class="oe_slogan">Configure Payment Acquirer</h2>
<div class="oe_span6">
<div class="oe_bg_img">
<img src="PaymentAcquirer.png" class="oe_picture oe_screenshot">
<img src="icon.png" class="oe_picture oe_screenshot">
</div>
</div>
<div class="oe_span6">
Expand Down Expand Up @@ -74,7 +74,7 @@ <h2 class="oe_slogan">Transaction Bitpay Details</h2>
</div>
<div class="oe_span6">
<div class="oe_bg_img">
<img src="BitpayTxDetails.png" class="oe_picture oe_screenshot">
<img src="icon.png" class="oe_picture oe_screenshot">
</div>
</div>
</div>
Expand All @@ -85,7 +85,7 @@ <h2 class="oe_slogan">Transaction Bitpay Details</h2>
<h2 class="oe_slogan">Instructions (First time running)</h2>
<div class="oe_span6">
<div class="oe_bg_img">
<img src="bitpay_pairingCode.png" class="oe_picture oe_screenshot">
<img src="icon.png" class="oe_picture oe_screenshot">
</div>
</div>
<div class="oe_span6">
Expand Down
File renamed without changes
109 changes: 109 additions & 0 deletions payment_stripe/static/src/js/stripe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
odoo.define('payment_stripe.stripe', function(require) {
"use strict";

var ajax = require('web.ajax');
var core = require('web.core');
var _t = core._t;
var qweb = core.qweb;
ajax.loadXML('/payment_stripe/static/src/xml/stripe_templates.xml', qweb);

// The following currencies are integer only, see
// https://stripe.com/docs/currencies#zero-decimal
var int_currencies = [
'BIF', 'XAF', 'XPF', 'CLP', 'KMF', 'DJF', 'GNF', 'JPY', 'MGA', 'PYGí',
'RWF', 'KRW', 'VUV', 'VND', 'XOF'
];

var handler = StripeCheckout.configure({
key: $("input[name='stripe_key']").val(),
image: $("input[name='stripe_image']").val(),
locale: 'auto',
closed: function() {
if (!handler.isTokenGenerate) {
$('#pay_stripe')
.removeAttr('disabled')
.find('i').remove();
}
},
token: function(token, args) {
handler.isTokenGenerate = true;
ajax.jsonRpc("/payment/stripe/create_charge", 'call', {
tokenid: token.id,
email: token.email,
amount: $("input[name='amount']").val(),
acquirer_id: $("#acquirer_stripe").val(),
currency: $("input[name='currency']").val(),
invoice_num: $("input[name='invoice_num']").val(),
return_url: $("input[name='return_url']").val()
}).done(function(data){
handler.isTokenGenerate = false;
window.location.href = data;
}).fail(function(){
var msg = arguments && arguments[1] && arguments[1].data && arguments[1].data.message;
var wizard = $(qweb.render('stripe.error', {'msg': msg || _t('Payment error')}));
wizard.appendTo($('body')).modal({'keyboard': true});
});
},
});

$('#pay_stripe').on('click', function(e) {
// Open Checkout with further options
if(!$(this).find('i').length)
$(this).append('<i class="fa fa-spinner fa-spin"/>');
$(this).attr('disabled','disabled');

var $form = $(e.currentTarget).parents('form');
var acquirer_id = $(e.currentTarget).closest('div.oe_sale_acquirer_button,div.oe_quote_acquirer_button,div.o_website_payment_new_payment');
acquirer_id = acquirer_id.data('id') || acquirer_id.data('acquirer_id');
if (! acquirer_id) {
return false;
}

var so_token = $("input[name='token']").val();
var so_id = $("input[name='return_url']").val().match(/quote\/([0-9]+)/) || undefined;
if (so_id) {
so_id = parseInt(so_id[1]);
}

e.preventDefault();
if ($('.o_website_payment').length !== 0) {
var currency = $("input[name='currency']").val();
var currency_id = $("input[name='currency_id']").val();
var amount = parseFloat($("input[name='amount']").val() || '0.0');

ajax.jsonRpc('/website_payment/transaction', 'call', {
reference: $("input[name='invoice_num']").val(),
amount: amount,
currency_id: currency_id,
acquirer_id: acquirer_id
})
handler.open({
name: $("input[name='merchant']").val(),
email: $("input[name='email']").val(),
description: $("input[name='invoice_num']").val(),
currency: currency,
amount: _.contains(int_currencies, currency) ? amount : amount * 100,
});
} else {
var currency = $("input[name='currency']").val();
var amount = parseFloat($("input[name='amount']").val() || '0.0');

ajax.jsonRpc('/shop/payment/transaction/' + acquirer_id, 'call', {
so_id: so_id,
so_token: so_token
}, {'async': false}).then(function (data) {
var $pay_stripe = $('#pay_stripe').detach();
$form.html(data);
// Restore 'Pay Now' button HTML since data might have changed it.
$form.find('#pay_stripe').replaceWith($pay_stripe);
handler.open({
name: $("input[name='merchant']").val(),
email: $("input[name='email']").val(),
description: $("input[name='invoice_num']").val(),
currency: currency,
amount: _.contains(int_currencies, currency) ? amount : amount * 100,
});
});
}
});
});
6 changes: 3 additions & 3 deletions payment_stripe/views/payment_stripe_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<data noupdate="1">

<template id="stripe_acquirer_button">
<form t-if="acquirer" t-att-action="tx_url" method="post" target="_self">
<!--<script src="https://checkout.stripe.com/checkout.js"></script>-->
<form t-if="acquirer" method="post" target="_self">
<script src="https://checkout.stripe.com/checkout.js"></script>
<input type='hidden' name='stripe_image' t-att-value="acquirer.stripe_image_url"/>
<input type='hidden' name='merchant' t-att-value='acquirer.company_id.name'/>
<input type='hidden' name='amount' t-att-value="amount"/>
Expand All @@ -25,7 +25,7 @@
<input type='hidden' name="stripe_key" t-att-value="acquirer.stripe_publishable_key"/>
<!-- Submit-->
<button id="pay_stripe" width="100px" t-att-class="submit_class">
<img t-if="not submit_txt" src="/payment_stripe/static/src/img/stripe_icon.png"/>
<img t-if="not submit_txt" src="/payment_stripe/description/icon.png"/>
<span t-if="submit_txt"><t t-esc="submit_txt"/> <span class="fa fa-long-arrow-right"/></span>
</button>
<script type="text/javascript" src="/payment_stripe/static/src/js/stripe.js"></script>
Expand Down

0 comments on commit 9e55649

Please sign in to comment.