Explorar el Código

Integration broker (#1968)

* [enhancement] integration borker and controller

* [minor][fix] parameter naming changes

* [fix] common scheduler for integration service

* [fix] integrations

* [patch] patch to move payment gateway in Integration Service

* [fix] add payment success, cancel and failuer handling pages

* [enhancment] dropbox integration merged in integration services

* provision to add custom parameters

* [fixes] patch fix to setup dropbox settings

* [fixes] removed dropbox backup, api usage note for paypal and razorpay

* [minor][fix] deprecate service events

* [fix] return type fix for checkout urls

* [fix] add custom settings via patch for dropbox backup frequency

* [fix] remove gride editting

* [enhance] ldap based login

* [enhance] login via ldap credentails

* [commit] remove parameter table, save params as json dict
pull/2/head
Saurabh hace 8 años
committed by Rushabh Mehta
commit
1e9d81b180
Se han modificado 10 ficheros con 220 adiciones y 0 borrados
  1. +27
    -0
      payments/public/js/razorpay.js
  2. +60
    -0
      payments/templates/includes/razorpay_checkout.js
  3. +0
    -0
      payments/templates/pages/__init__.py
  4. +12
    -0
      payments/templates/pages/payment-cancel.html
  5. +12
    -0
      payments/templates/pages/payment-failed.html
  6. +12
    -0
      payments/templates/pages/payment-success.html
  7. +12
    -0
      payments/templates/pages/payment_cancel.py
  8. +9
    -0
      payments/templates/pages/payment_success.py
  9. +28
    -0
      payments/templates/pages/razorpay_checkout.html
  10. +48
    -0
      payments/templates/pages/razorpay_checkout.py

+ 27
- 0
payments/public/js/razorpay.js Ver fichero

@@ -0,0 +1,27 @@
frappe.provide("frappe.integration_service")

frappe.integration_service.razorpay = {
load: function(frm) {
new frappe.integration_service.Razorpay(frm)
},
scheduler_job_helper: function(){
return {
"Execute on every few minits of interval": "Take backup of database and files to dropbox on daily basis"
}
}
}

frappe.integration_service.Razorpay = Class.extend({
init:function(frm){
this.frm = frm;
this.frm.toggle_display("use_test_account", false);
this.show_logs();
},
show_logs: function(){
this.frm.add_custom_button(__("Show Log"), function(frm){
frappe.route_options = {"integration_request_service": "Razorpay"};
frappe.set_route("List", "Integration Request");
}).addClass("btn-primary")
}
})

+ 60
- 0
payments/templates/includes/razorpay_checkout.js Ver fichero

@@ -0,0 +1,60 @@
$(document).ready(function(){
(function(e){
var options = {
"key": "{{ api_key }}",
"amount": cint({{ amount }} * 100), // 2000 paise = INR 20
"name": "{{ title }}",
"description": "{{ description }}",
"image": "{{ brand_image }}",
"handler": function (response){
razorpay.make_payment_log(response, options, "{{ reference_doctype }}", "{{ reference_docname }}");
},
"prefill": {
"name": "{{ payer_name }}",
"email": "saurabh@erpnext.com",
"order_id": "{{ order_id }}",
"phone": "9773595372"
},
"notes": {
"doctype": "{{ doctype }}",
"name": "{{ name }}",
"payment_request": "{{ name }}" // backward compatibility
},
"theme": {
"color": "#4B4C9D"
}
};

var rzp = new Razorpay(options);
console.log(options)
rzp.open();
// e.preventDefault();
})();
})

frappe.provide('razorpay');

razorpay.make_payment_log = function(response, options, doctype, docname){
$('.razorpay-loading').addClass('hidden');
$('.razorpay-confirming').removeClass('hidden');

frappe.call({
method:"frappe.templates.pages.razorpay_checkout.make_payment",
freeze:true,
headers: {"X-Requested-With": "XMLHttpRequest"},
args: {
"razorpay_payment_id": response.razorpay_payment_id,
"options": options,
"reference_doctype": doctype,
"reference_docname": docname
},
callback: function(r){
if (r.message && r.message.status == 200) {
window.location.href = r.message.redirect_to
}
else if (r.message && ([401,400,500].indexOf(r.message.status) > -1)) {
window.location.href = r.message.redirect_to
}
}
})
}

+ 0
- 0
payments/templates/pages/__init__.py Ver fichero


+ 12
- 0
payments/templates/pages/payment-cancel.html Ver fichero

@@ -0,0 +1,12 @@
{% extends "templates/web.html" %}

{% block title %}Make Payment{% endblock %}

{%- block header -%}
<h2>Payment Cancelled<h2>
{% endblock %}

{%- block page_content -%}
<p>You have cancelled your payment.</p>
<p><br><a href="/">Back to home page</a></p>
{% endblock %}

+ 12
- 0
payments/templates/pages/payment-failed.html Ver fichero

@@ -0,0 +1,12 @@
{% extends "templates/web.html" %}

{% block title %}Payment Failed{% endblock %}

{%- block header -%}
<h2>Payment Failed<h2>
{% endblock %}

{%- block page_content -%}
<p class="lead">Your payment has failed. Do you mind trying again?</p>
<p><a href="/" class="btn btn-default">Back to Home</a></p>
{% endblock %}

+ 12
- 0
payments/templates/pages/payment-success.html Ver fichero

@@ -0,0 +1,12 @@
{% extends "templates/web.html" %}

{% block title %}Payment Success{% endblock %}

{%- block header -%}
<h2>Payment Success<h2>
{% endblock %}

{%- block page_content -%}
<p class="lead">Your payment has succeeded.</p>
<p><a href="/" class="btn btn-default">Back to Home</a></p>
{% endblock %}

+ 12
- 0
payments/templates/pages/payment_cancel.py Ver fichero

@@ -0,0 +1,12 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

from __future__ import unicode_literals
import frappe

def get_context(context):
token = frappe.local.form_dict.token

if token:
frappe.db.set_value("Integration Request", token, "status", "Cancelled")
frappe.db.commit()

+ 9
- 0
payments/templates/pages/payment_success.py Ver fichero

@@ -0,0 +1,9 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

from __future__ import unicode_literals

import frappe

def get_context(context):
token = frappe.local.form_dict.token

+ 28
- 0
payments/templates/pages/razorpay_checkout.html Ver fichero

@@ -0,0 +1,28 @@
{% extends "templates/web.html" %}

{% block title %} Payment {% endblock %}

{%- block header -%}{% endblock %}

{% block script %}
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
<script>{% include "templates/includes/integrations/razorpay_checkout.js" %}</script>
{% endblock %}

{%- block page_content -%}

<p class='lead text-center centered'>
<span class='razorpay-loading'>Loading Payment System</span>
<span class='razorpay-confirming hidden'>Confirming Payment</span>
</p>

{% endblock %}

{% block style %}
<style>
header, footer {
display: none;
}

</style>
{% endblock %}

+ 48
- 0
payments/templates/pages/razorpay_checkout.py Ver fichero

@@ -0,0 +1,48 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import get_url, flt
import json, urllib

from frappe.integrations.razorpay import Controller

no_cache = 1
no_sitemap = 1

expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'reference_docname',
'payer_name', 'payer_email', 'order_id')

def get_context(context):
context.no_cache = 1
context.api_key = Controller().get_settings().api_key

context.brand_image = './assets/erpnext/images/erp-icon.svg'

# all these keys exist in form_dict
if not (set(expected_keys) - set(frappe.form_dict.keys())):
for key in expected_keys:
context[key] = frappe.form_dict[key]

context['amount'] = flt(context['amount'])

else:
frappe.redirect_to_message(_('Some information is missing'), _('Looks like someone sent you to an incomplete URL. Please ask them to look into it.'))
frappe.local.flags.redirect_location = frappe.local.response.location
raise frappe.Redirect

@frappe.whitelist(allow_guest=True)
def make_payment(razorpay_payment_id, options, reference_doctype, reference_docname):
data = {}
if isinstance(options, basestring):
data = json.loads(options)
data.update({
"razorpay_payment_id": razorpay_payment_id,
"reference_docname": reference_docname,
"reference_doctype": reference_doctype
})
return Controller().create_request(data)

Cargando…
Cancelar
Guardar