Kaynağa Gözat

Allow several Stripe accounts (#5573)

* Allow several Stripe accounts

* Addition of a sync patch

* Remove unused dependancy
pull/2/head
Charles-Henri Decultot 7 yıl önce
committed by Rushabh Mehta
ebeveyn
işleme
6b81c3cefa
5 değiştirilmiş dosya ile 94 ekleme ve 18 silme
  1. +40
    -5
      payments/payment_gateways/doctype/stripe_settings/stripe_settings.json
  2. +13
    -8
      payments/payment_gateways/doctype/stripe_settings/stripe_settings.py
  3. +23
    -0
      payments/payment_gateways/doctype/stripe_settings/test_stripe_settings.js
  4. +9
    -0
      payments/payment_gateways/doctype/stripe_settings/test_stripe_settings.py
  5. +9
    -5
      payments/templates/pages/stripe_checkout.py

+ 40
- 5
payments/payment_gateways/doctype/stripe_settings/stripe_settings.json Dosyayı Görüntüle

@@ -3,6 +3,7 @@
"allow_guest_to_view": 0,
"allow_import": 0,
"allow_rename": 0,
"autoname": "field:gateway_name",
"beta": 0,
"creation": "2017-03-09 17:18:29.458397",
"custom": 0,
@@ -13,6 +14,38 @@
"engine": "InnoDB",
"fields": [
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"columns": 0,
"fieldname": "gateway_name",
"fieldtype": "Data",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Payment Gateway Name",
"length": 0,
"no_copy": 0,
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"remember_last_selected_value": 0,
"report_hide": 0,
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -24,7 +57,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Publishable Key",
"length": 0,
@@ -39,9 +72,11 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
},
{
"allow_bulk_edit": 0,
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
@@ -53,7 +88,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_global_search": 0,
"in_list_view": 0,
"in_list_view": 1,
"in_standard_filter": 0,
"label": "Secret Key",
"length": 0,
@@ -68,6 +103,7 @@
"reqd": 1,
"search_index": 0,
"set_only_once": 0,
"translatable": 0,
"unique": 0
}
],
@@ -78,10 +114,10 @@
"image_view": 0,
"in_create": 0,
"is_submittable": 0,
"issingle": 1,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
"modified": "2017-03-09 17:19:25.087475",
"modified": "2018-05-18 16:18:32.584083",
"modified_by": "Administrator",
"module": "Integrations",
"name": "Stripe Settings",
@@ -90,7 +126,6 @@
"permissions": [
{
"amend": 0,
"apply_user_permissions": 0,
"cancel": 0,
"create": 1,
"delete": 1,


+ 13
- 8
payments/payment_gateways/doctype/stripe_settings/stripe_settings.py Dosyayı Görüntüle

@@ -29,9 +29,9 @@ class StripeSettings(Document):
'GBP': 0.30, 'NZD': 0.50, 'SGD': 0.50
}

def validate(self):
create_payment_gateway('Stripe')
call_hook_method('payment_gateway_enabled', gateway='Stripe')
def on_update(self):
create_payment_gateway('Stripe-' + self.gateway_name, settings='Stripe Settings', controller=self.gateway_name)
call_hook_method('payment_gateway_enabled', gateway='Stripe-' + self.gateway_name)
if not self.flags.ignore_mandatory:
self.validate_stripe_credentails()

@@ -55,7 +55,7 @@ class StripeSettings(Document):

def get_payment_url(self, **kwargs):
return get_url("./integrations/stripe_checkout?{0}".format(urlencode(kwargs)))
def create_request(self, data):
self.data = frappe._dict(data)

@@ -68,24 +68,24 @@ class StripeSettings(Document):
"redirect_to": frappe.redirect_to_message(_('Server Error'), _("Seems issue with server's razorpay config. Don't worry, in case of failure amount will get refunded to your account.")),
"status": 401
}
def create_charge_on_stripe(self):
headers = {"Authorization":
"Bearer {0}".format(self.get_password(fieldname="secret_key", raise_exception=False))}
data = {
"amount": cint(flt(self.data.amount)*100),
"currency": self.data.currency,
"source": self.data.stripe_token_id,
"description": self.data.description
}
redirect_to = self.data.get('redirect_to') or None
redirect_message = self.data.get('redirect_message') or None

try:
resp = make_post_request(url="https://api.stripe.com/v1/charges", headers=headers, data=data)
if resp.get("captured") == True:
self.integration_request.db_set('status', 'Completed', update_modified=False)
self.flags.status_changed_to = "Completed"
@@ -125,3 +125,8 @@ class StripeSettings(Document):
"redirect_to": redirect_url,
"status": status
}

def get_gateway_controller(doc):
payment_request = frappe.get_doc("Payment Request", doc)
gateway_controller = frappe.db.get_value("Payment Gateway", payment_request.payment_gateway, "gateway_controller")
return gateway_controller

+ 23
- 0
payments/payment_gateways/doctype/stripe_settings/test_stripe_settings.js Dosyayı Görüntüle

@@ -0,0 +1,23 @@
/* eslint-disable */
// rename this file from _test_[name] to test_[name] to activate
// and remove above this line

QUnit.test("test: Stripe Settings", function (assert) {
let done = assert.async();

// number of asserts
assert.expect(1);

frappe.run_serially([
// insert a new Stripe Settings
() => frappe.tests.make('Stripe Settings', [
// values to be set
{key: 'value'}
]),
() => {
assert.equal(cur_frm.doc.key, 'value');
},
() => done()
]);

});

+ 9
- 0
payments/payment_gateways/doctype/stripe_settings/test_stripe_settings.py Dosyayı Görüntüle

@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2018, Frappe Technologies and Contributors
# See license.txt
from __future__ import unicode_literals

import unittest

class TestStripeSettings(unittest.TestCase):
pass

+ 9
- 5
payments/templates/pages/stripe_checkout.py Dosyayı Görüntüle

@@ -5,6 +5,7 @@ import frappe
from frappe import _
from frappe.utils import flt, cint
import json
from frappe.integrations.doctype.stripe_settings.stripe_settings import get_gateway_controller

no_cache = 1
no_sitemap = 1
@@ -14,13 +15,14 @@ expected_keys = ('amount', 'title', 'description', 'reference_doctype', 'referen

def get_context(context):
context.no_cache = 1
context.publishable_key = get_api_key()

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

context.publishable_key = get_api_key(context.reference_docname)

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

else:
@@ -29,8 +31,9 @@ def get_context(context):
frappe.local.flags.redirect_location = frappe.local.response.location
raise frappe.Redirect

def get_api_key():
publishable_key = frappe.db.get_value("Stripe Settings", None, "publishable_key")
def get_api_key(doc):
gateway_controller = get_gateway_controller(doc)
publishable_key = frappe.db.get_value("Stripe Settings", gateway_controller, "publishable_key")
if cint(frappe.form_dict.get("use_sandbox")):
publishable_key = frappe.conf.sandbox_publishable_key

@@ -44,6 +47,7 @@ def make_payment(stripe_token_id, data, reference_doctype=None, reference_docnam
"stripe_token_id": stripe_token_id
})

data = frappe.get_doc("Stripe Settings").create_request(data)
gateway_controller = get_gateway_controller(reference_docname)
data = frappe.get_doc("Stripe Settings", gateway_controller).create_request(data)
frappe.db.commit()
return data
return data

Yükleniyor…
İptal
Kaydet