Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vjFaLk committed Sep 26, 2017
2 parents ee5d6b5 + dc94691 commit bfec96a
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 57 deletions.
2 changes: 1 addition & 1 deletion gateway_selector/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__version__ = '0.0.1'
__version__ = '1.0.0'

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"beta": 0,
Expand All @@ -12,6 +13,7 @@
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -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,
Expand All @@ -41,6 +44,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -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",
Expand All @@ -69,6 +74,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -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",
Expand All @@ -97,6 +104,7 @@
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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
}
33 changes: 17 additions & 16 deletions ..._selector/gateway_selector/doctype/gateway_selector_settings/gateway_selector_settings.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@
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.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_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)
Expand Down Expand Up @@ -84,11 +85,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)

Expand All @@ -97,7 +98,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)
Expand All @@ -107,7 +108,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:
Expand All @@ -116,7 +117,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)

Expand All @@ -126,7 +127,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):
Expand Down
7 changes: 6 additions & 1 deletion gateway_selector/public/css/select.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@
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;
overflow: hidden;
padding: 0;
}

#gateway-selector-continue.paypal:hover {
border: 1px solid red;
}

.gateway-error {
background: #ff5959;
color: white;
Expand Down
19 changes: 10 additions & 9 deletions gateway_selector/public/js/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -255,6 +255,7 @@ frappe.integration_service.gateway_selector_gateway = Class.extend({

$('#gateway-selector-continue').click(function() {

$('html, body').animate({ scrollTop: $('#awc-forms, #gateway-selector-forms').first().offset().top - 60 }, 'slow');
if ( !base._is_enabled ) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<div id="billing-addrs">
<div id="awc-billing-addrs">
<h4>Select Billing Address</h4>
<div class="row">
{% if not addresses %}
<div class="addresses-container"></div>
<div class="awc-addresses-container"></div>
{% else %}
<div class="addresses-container">
<div class="awc-addresses-container">
{% for address in addresses%}
<div class="col-md-12 col-sm-12 address-item">
<div class="col-md-12 col-sm-12 awc-address-item">
<div class="well">
<div data-name="{{ address.name }}" class="addr" style="cursor: pointer">
<div data-name="{{ address.name }}" class="awc-addr" style="cursor: pointer">
<p>
<button title="Delete" class="pull-right delete"><span class="fa fa-trash" aria-hidden="true"></span></button>
<button title="Edit" data-type="bill" class="pull-right edit" style="margin:0 15px;"><span class="fa fa-pencil" aria-hidden="true"></span></button>
<button title="Delete" class="pull-right awc-delete"><span class="fa fa-trash" aria-hidden="true"></span></button>
<button title="Edit" data-type="bill" class="pull-right awc-edit" style="margin:0 15px;"><span class="fa fa-pencil" aria-hidden="true"></span></button>
<span id="line1">{{ address.address_line1 }}</span>, {% if address.address_line2 %}
<span id="line2">{{ address.address_line2 }}</span>, {% endif %}
<span id="city">{{ address.city }}</span>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>Select Payment Method</h2>
<h2>Billing Address</h2>
<div class="row">
<div id="select-bill-addr">
{% include "templates/includes/integrations/gateway_selector/billing_address_select.html" with context %}
<div id="awc-billing-addrs"></div>
</div>
<div id="form-bill-addr" style="display: none;">
{% include "templates/includes/integrations/gateway_selector/billing_address.html" with context %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from frappe.utils.formatters import format_value
from awesome_cart.compat.customer import get_current_customer
from awesome_cart.session import get_awc_session, set_awc_session
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 gateway_selector import payments
import json
Expand All @@ -27,8 +26,6 @@ def get_context(context):
awc_session = get_awc_session()
pr_access = awc_session.get("gateway_selector_pr_access")

print(pretty_json(awc_session))

# or from pathname, this works better for redirection on auth errors
if not proxy_name:
path_parts = context.get("pathname", "").split('/')
Expand Down Expand Up @@ -76,11 +73,6 @@ def get_context(context):
default_country = frappe.get_value("System Settings", "System Settings", "country")
default_country_doc = next((x for x in context["billing_countries"] if x.name == default_country), None)

customer = get_current_customer()

if customer:
context["addresses"] = frappe.get_all("Address", filters={"customer" : customer.name, "disabled" : 0, "address_type" : "Billing"}, fields="*")

country_idx = context["billing_countries"].index(default_country_doc)
context["billing_countries"].pop(country_idx)
context["billing_countries"] = [default_country_doc] + context["billing_countries"]
Expand Down
12 changes: 1 addition & 11 deletions gateway_selector/templates/pages/payments.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,16 +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 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

import json

no_cache = 1
no_sitemap = 1
Expand All @@ -30,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)
Expand Down

0 comments on commit bfec96a

Please sign in to comment.