From caec083a35eb72fbe00dbfe7d654e348f89086a3 Mon Sep 17 00:00:00 2001 From: Valmik Jangla Date: Mon, 28 Aug 2017 21:17:20 +0530 Subject: [PATCH 1/8] Move Payments to v8 API --- .../gateway_selector_item.json | 17 +++++++++-- .../gateway_selector_settings.py | 30 ++++++++++--------- gateway_selector/templates/pages/payments.py | 1 - 3 files changed, 30 insertions(+), 18 deletions(-) mode change 100644 => 100755 gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py diff --git a/gateway_selector/gateway_selector/doctype/gateway_selector_item/gateway_selector_item.json b/gateway_selector/gateway_selector/doctype/gateway_selector_item/gateway_selector_item.json index db4903d..d495043 100644 --- a/gateway_selector/gateway_selector/doctype/gateway_selector_item/gateway_selector_item.json +++ b/gateway_selector/gateway_selector/doctype/gateway_selector_item/gateway_selector_item.json @@ -1,5 +1,6 @@ { "allow_copy": 0, + "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, "beta": 0, @@ -12,6 +13,7 @@ "engine": "InnoDB", "fields": [ { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -22,12 +24,13 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, "label": "Gateway Service", "length": 0, "no_copy": 0, - "options": "Integration Service", + "options": "Payment Gateway", "permlevel": 0, "precision": "", "print_hide": 0, @@ -41,6 +44,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -51,6 +55,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, "label": "Label", @@ -69,6 +74,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -79,6 +85,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Icon", @@ -97,6 +104,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -108,6 +116,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, "label": "Default", @@ -126,17 +135,17 @@ "unique": 0 } ], + "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, "idx": 0, "image_view": 0, "in_create": 0, - "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-03-09 15:46:11.689274", + "modified": "2017-08-28 07:00:32.710946", "modified_by": "Administrator", "module": "Gateway Selector", "name": "Gateway Selector Item", @@ -146,7 +155,9 @@ "quick_entry": 1, "read_only": 0, "read_only_onload": 0, + "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", + "track_changes": 1, "track_seen": 0 } \ No newline at end of file diff --git a/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py b/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py old mode 100644 new mode 100755 index 06bb7fc..049b054 --- a/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py +++ b/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py @@ -10,24 +10,26 @@ from frappe.utils import get_url, call_hook_method, cint, flt from urllib import urlencode from awesome_cart.compat.customer import get_current_customer -from frappe.integration_broker.doctype.integration_service.integration_service import IntegrationService, get_integration_controller +from frappe.integrations.utils import get_payment_gateway_controller +from frappe.integrations.utils import create_request_log, create_payment_gateway -class GatewaySelectorSettings(IntegrationService): +class GatewaySelectorSettings(Document): service_name = "Gateway Selector" def validate(self): - pass + create_payment_gateway("Gateway Selector") + call_hook_method("payment_gateway_enabled", gateway=self.service_name) + def on_update(self): pass - def enable(self): - call_hook_method("payment_gateway_enabled", gateway=self.service_name) def validate_transaction_currency(self, currency): - for gateway in self.gateways: - controller = get_integration_controller(gateway.service) - controller.validate_transaction_currency(currency) + pass + # for gateway in self.gateways: + # controller = get_payment_gateway_controller(gateway.service) + # controller.validate_transaction_currency(currency) def get_payment_url(self, **kwargs): proxy = self.build_proxy(**kwargs) @@ -84,11 +86,11 @@ def get_awc_gateway_form(context={}): def is_gateway_embedable(name): """Returns True if the the gateway supports get_embed_form api""" - controller = get_integration_controller(name) + controller = get_payment_gateway_controller(name) return hasattr(controller, "is_embedable") and controller.is_embedable def is_gateway_available(name, context, is_backend=0): - controller = get_integration_controller(name) + controller = get_payment_gateway_controller(name) if hasattr(controller, "is_available"): return controller.is_available(context, is_backend=is_backend) @@ -97,7 +99,7 @@ def is_gateway_available(name, context, is_backend=0): def get_gateway_embed_form(name, context={}): """Gets the gateway's embedable form information""" - controller = get_integration_controller(name) + controller = get_payment_gateway_controller(name) return controller.get_embed_form(context=context) @frappe.whitelist(allow_guest=True) @@ -107,7 +109,7 @@ def get_url_from_gateway(gateway, data): if isinstance(data, unicode) or isinstance(data, str): data = json.loads(data) - gateway_selector = get_integration_controller("Gateway Selector") + gateway_selector = get_payment_gateway_controller("Gateway Selector") for g in gateway_selector.gateways: if g.service.replace(' ', '_').lower() == gateway: @@ -116,7 +118,7 @@ def get_url_from_gateway(gateway, data): else: gateway_name = None - controller = get_integration_controller(gateway_name) + controller = get_payment_gateway_controller(gateway_name) return controller.get_payment_url(**data) @@ -126,7 +128,7 @@ def get_gateways(context="{}", is_backend=0): context = json.loads(context) context['is_backend'] = is_backend - gateway_selector = get_integration_controller("Gateway Selector") + gateway_selector = get_payment_gateway_controller("Gateway Selector") gateways = [] for gateway in gateway_selector.gateways: if is_gateway_available(gateway.service, context, is_backend=is_backend): diff --git a/gateway_selector/templates/pages/payments.py b/gateway_selector/templates/pages/payments.py index 4e936d9..aa3dfa0 100644 --- a/gateway_selector/templates/pages/payments.py +++ b/gateway_selector/templates/pages/payments.py @@ -5,7 +5,6 @@ from frappe.utils import flt, cint from frappe.utils.formatters import format_value from awesome_cart.compat.customer import get_current_customer -from frappe.integration_broker.doctype.integration_service.integration_service import get_integration_controller from gateway_selector.gateway_selector.doctype.gateway_selector_settings.gateway_selector_settings import is_gateway_embedable, build_embed_context from dti_devtools.debug import log, pretty_json From f95291c01dae4c8d2a7ee54d713bb074a5874965 Mon Sep 17 00:00:00 2001 From: Valmik Jangla Date: Tue, 29 Aug 2017 04:23:49 -0700 Subject: [PATCH 2/8] Code cleanup --- .../gateway_selector_settings.py | 5 ++--- gateway_selector/templates/pages/payments.py | 11 +---------- 2 files changed, 3 insertions(+), 13 deletions(-) mode change 100644 => 100755 gateway_selector/templates/pages/payments.py diff --git a/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py b/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py index 049b054..57d28fb 100755 --- a/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py +++ b/gateway_selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py @@ -7,11 +7,10 @@ import json from frappe import _dict from frappe.model.document import Document -from frappe.utils import get_url, call_hook_method, cint, flt -from urllib import urlencode +from frappe.utils import get_url, call_hook_method from awesome_cart.compat.customer import get_current_customer from frappe.integrations.utils import get_payment_gateway_controller -from frappe.integrations.utils import create_request_log, create_payment_gateway +from frappe.integrations.utils import create_payment_gateway class GatewaySelectorSettings(Document): service_name = "Gateway Selector" diff --git a/gateway_selector/templates/pages/payments.py b/gateway_selector/templates/pages/payments.py old mode 100644 new mode 100755 index aa3dfa0..cdc5cc2 --- a/gateway_selector/templates/pages/payments.py +++ b/gateway_selector/templates/pages/payments.py @@ -1,15 +1,6 @@ from __future__ import unicode_literals, absolute_import import frappe -from frappe import _ -from frappe.utils import flt, cint -from frappe.utils.formatters import format_value -from awesome_cart.compat.customer import get_current_customer -from gateway_selector.gateway_selector.doctype.gateway_selector_settings.gateway_selector_settings import is_gateway_embedable, build_embed_context - -from dti_devtools.debug import log, pretty_json - -import json no_cache = 1 no_sitemap = 1 @@ -29,7 +20,7 @@ def get_context(context): try: proxy = frappe.get_doc("Gateway Selector Proxy", proxy_name) payment_request_name = proxy.get("reference_docname") - except Exception as ex: + except: proxy = None context["payment_request_name"] = form.get("payment_request_name", payment_request_name) From ceac8bbf404b14fdec1b4b3f0591199ee0fafaaa Mon Sep 17 00:00:00 2001 From: Felipe Orellana Date: Thu, 14 Sep 2017 22:27:13 +0000 Subject: [PATCH 3/8] [FIX] Fixes issue where paypal css gets overriden causing paypal button to dissapear --- gateway_selector/public/css/select.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gateway_selector/public/css/select.css b/gateway_selector/public/css/select.css index 5c72474..28d5e32 100644 --- a/gateway_selector/public/css/select.css +++ b/gateway_selector/public/css/select.css @@ -11,9 +11,10 @@ margin-top: 1em; } +#gateway-selector-continue.paypal:hover, #gateway-selector-continue.paypal { display: inline-block; - background: url(https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png) center center no-repeat transparent; + background: url(https://www.paypalobjects.com/webstatic/en_US/i/buttons/checkout-logo-medium.png) center center no-repeat transparent !important; width: 170px; height: 32px; text-indent: -10000000em; @@ -21,6 +22,10 @@ padding: 0; } +#gateway-selector-continue.paypal:hover { + border: 1px solid red; +} + .gateway-error { background: #ff5959; color: white; From 1cfcd1aca247ef957087d44d04862caa80e91b95 Mon Sep 17 00:00:00 2001 From: Sushant Nadkar Date: Tue, 19 Sep 2017 15:53:07 +0530 Subject: [PATCH 4/8] Refactored CSS to have custom prefixes in awc --- gateway_selector/public/js/base.js | 20 +++++++++---------- .../billing_address_select.html | 14 ++++++------- .../integrations/gateway_selector/embed.html | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/gateway_selector/public/js/base.js b/gateway_selector/public/js/base.js index 27364e3..eb289ff 100644 --- a/gateway_selector/public/js/base.js +++ b/gateway_selector/public/js/base.js @@ -44,15 +44,15 @@ frappe.gateway_selector.AddressFormProvider = Class.extend({ this.data.pincode = $form.find('input[name="pincode"]').val(); this.data.country = $form.find('select[name="country"] option:checked').attr('value'); } else { - this.data.billing_address = $('#billing-addrs div.selected').attr('data-name'); - this.data.title = $('#billing-addrs .selected span#title strong').text(); - this.data.phone = $('#billing-addrs .selected span#phone').text(); - this.data.address_1 = $('#billing-addrs .selected span#line1').text(); - this.data.address_2 = $('#billing-addrs .selected span#line2').text(); - this.data.city = $('#billing-addrs .selected span#city').text(); - this.data.state = $('#billing-addrs .selected span#state').text(); - this.data.pincode = $('#billing-addrs .selected span#postal_code').text(); - this.data.country = $('#billing-addrs .selected span#country').text(); + this.data.billing_address = $('#awc-billing-addrs div.awc-selected').attr('data-name'); + this.data.title = $('#awc-billing-addrs .awc-selected span#title strong').text(); + this.data.phone = $('#awc-billing-addrs .awc-selected span#phone').text(); + this.data.address_1 = $('#awc-billing-addrs .awc-selected span#line1').text(); + this.data.address_2 = $('#awc-billing-addrs .awc-selected span#line2').text(); + this.data.city = $('#awc-billing-addrs .awc-selected span#city').text(); + this.data.state = $('#awc-billing-addrs .awc-selected span#state').text(); + this.data.pincode = $('#awc-billing-addrs .awc-selected span#postal_code').text(); + this.data.country = $('#awc-billing-addrs .awc-selected span#country').text(); } $form.trigger('address_change', this.data); @@ -254,7 +254,7 @@ frappe.integration_service.gateway_selector_gateway = Class.extend({ }) $('#gateway-selector-continue').click(function() { - + $('html, body').animate({ scrollTop: $('#awc-forms').offset().top - 60 }, 'slow'); if ( !base._is_enabled ) { return; } diff --git a/gateway_selector/templates/includes/integrations/gateway_selector/billing_address_select.html b/gateway_selector/templates/includes/integrations/gateway_selector/billing_address_select.html index e9de53a..153cb69 100644 --- a/gateway_selector/templates/includes/integrations/gateway_selector/billing_address_select.html +++ b/gateway_selector/templates/includes/integrations/gateway_selector/billing_address_select.html @@ -1,17 +1,17 @@ -
+

Select Billing Address

{% if not addresses %} -
+
{% else %} -
+
{% for address in addresses%} -
+
-
+

- - + + {{ address.address_line1 }}, {% if address.address_line2 %} {{ address.address_line2 }}, {% endif %} {{ address.city }}, diff --git a/gateway_selector/templates/includes/integrations/gateway_selector/embed.html b/gateway_selector/templates/includes/integrations/gateway_selector/embed.html index 9c8f81f..a548cbd 100644 --- a/gateway_selector/templates/includes/integrations/gateway_selector/embed.html +++ b/gateway_selector/templates/includes/integrations/gateway_selector/embed.html @@ -20,7 +20,7 @@

Select Payment Method

{% if not is_backend %}

Billing Address

-
+
{% include "templates/includes/integrations/gateway_selector/billing_address_select.html" with context %}