def test_uses_app_info(self, requestor, mock_response, check_call): try: old = stripe.app_info stripe.set_app_info( "MyAwesomePlugin", url="https://myawesomeplugin.info", version="1.2.34", partner_id="partner_12345", ) mock_response("{}", 200) requestor.request("get", self.valid_path, {}) ua = "Stripe/v1 PythonBindings/%s" % (stripe.version.VERSION,) ua += " MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)" header_matcher = APIHeaderMatcher( user_agent=ua, app_info={ "name": "MyAwesomePlugin", "url": "https://myawesomeplugin.info", "version": "1.2.34", "partner_id": "partner_12345", }, ) check_call("get", headers=header_matcher) finally: stripe.app_info = old
def test_uses_app_info(self, requestor, mock_response, check_call): try: old = stripe.app_info stripe.set_app_info( 'MyAwesomePlugin', url='https://myawesomeplugin.info', version='1.2.34', partner_id='partner_12345', ) mock_response('{}', 200) requestor.request('get', self.valid_path, {}) ua = "Stripe/v1 PythonBindings/%s" % (stripe.version.VERSION, ) ua += " MyAwesomePlugin/1.2.34 (https://myawesomeplugin.info)" header_matcher = APIHeaderMatcher( user_agent=ua, app_info={ 'name': 'MyAwesomePlugin', 'url': 'https://myawesomeplugin.info', 'version': '1.2.34', 'partner_id': 'partner_12345', }) check_call('get', headers=header_matcher) finally: stripe.app_info = old
def purchase(): """Ajax function called when a customer orders and pays for the cart.""" if not URL.verify(request, hmac_key=session.hmac_key): raise HTTP(500) # Creates the charge. import stripe stripe.set_app_info('Luca de Alfaro teaching site', version="2.0", url="http://www.soe.ucsc.edu/~luca") # Your secret key. stripe.api_key = STRIPE_KEY_INFO['private_key'] token = json.loads(request.vars.transaction_token) amount = float(request.vars.amount) try: charge = stripe.Charge.create( amount=int(amount * 100), currency="usd", source=token['id'], description="Purchase", ) logger.info("The charge was successful") except stripe.error.CardError as e: logger.info("The card has been declined.") logger.info("%r" % traceback.format_exc()) return response.json(dict(result="nok")) db.customer_order.insert(customer_info=request.vars.customer_info, transaction_token=json.dumps(token), cart=request.vars.cart) return response.json(dict(result="ok"))
def configure_stripe_client(): stripe.set_app_info( Context.config.get('user_agent', 'Singer.io Tap'), url="https://github.com/singer-io/tap-stripe", ) # Set the API key we'll be using # https://github.com/stripe/stripe-python/tree/a9a8d754b73ad47bdece6ac4b4850822fa19db4e#usage stripe.api_key = Context.config.get('client_secret') # Override the Stripe API Version for consistent access stripe.api_version = '2019-10-08' # Allow ourselves to retry retriable network errors 5 times # https://github.com/stripe/stripe-python/tree/a9a8d754b73ad47bdece6ac4b4850822fa19db4e#configuring-automatic-retries stripe.max_network_retries = 15 # Configure client with a default timeout of 80 seconds client = stripe.http_client.RequestsClient() apply_request_timer_to_client(client) stripe.default_http_client = client # Set stripe logging to INFO level # https://github.com/stripe/stripe-python/tree/a9a8d754b73ad47bdece6ac4b4850822fa19db4e#logging logging.getLogger('stripe').setLevel(logging.INFO) # Verify connectivity account = stripe.Account.retrieve(Context.config.get('account_id')) LOGGER.info( "Successfully connected to Stripe Account with name `%s`", account.business_profile.name, )
def _init_api(self): stripe.api_version = '2019-05-16' stripe.set_app_info( "pretix", partner_id="pp_partner_FSaz4PpKIur7Ox", version=__version__, url="https://pretix.eu" )
def ready(self): import stripe from . import checks, event_handlers # noqa: Register the checks and event handlers # Set app info # https://stripe.com/docs/building-plugins#setappinfo stripe.set_app_info("dj-stripe", version=__version__, url="https://github.com/dj-stripe/dj-stripe")
def setup_stripe_data(cr, registry): import stripe stripe.set_app_info( "ODOO Webkul Stripe Payment Acquirer", version=stripe.version.VERSION, url="https://webkul.com/", # partner_id='partner_12345' ) create_missing_journal_for_acquirers(cr, registry)
def ready(self): import stripe from . import checks, event_handlers # noqa: Register the checks and event handlers # Set app info # https://stripe.com/docs/building-plugins#setappinfo stripe.set_app_info( "dj-stripe", version=__version__, url="https://github.com/dj-stripe/dj-stripe" )
def ready(self) -> None: from . import settings # Stripe library setup stripe.api_key = settings.SECRET_KEY stripe.api_version = settings.API_VERSION # Identify the plugin to Stripe stripe.set_app_info( "django-stripe-lite", version=__version__, url="https://github.com/yunojuno/django-stripe-lite", )
""" Python 3.6 or newer required. """ import stripe import json import os from flask import Flask, render_template, jsonify, request, send_from_directory from dotenv import load_dotenv, find_dotenv # Setup Stripe python client library load_dotenv(find_dotenv()) # For sample support and debugging, not required for production: stripe.set_app_info( 'stripe-samples/subscription-use-cases/fixed-price', version='0.0.1', url='https://github.com/stripe-samples/subscription-use-cases/fixed-price') stripe.api_version = '2020-08-27' stripe.api_key = os.getenv('STRIPE_SECRET_KEY') static_dir = str(os.path.abspath(os.path.join(__file__, "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_index(): return render_template('register.html') @app.route('/config', methods=['GET'])
def ready(self): stripe.api_key = settings.STRIPE_SECRET_KEY stripe_app_data = settings.STRIPE_APP_DATA stripe.set_app_info(**stripe_app_data) from . import signal_receivers
""" .. module:: djstripe. :synopsis: dj-stripe - Django + Stripe Made Easy """ from __future__ import absolute_import, division, print_function, unicode_literals import pkg_resources import stripe from . import checks # noqa: Register the checks __version__ = pkg_resources.require("dj-stripe")[0].version # Set app info # https://stripe.com/docs/building-plugins#setappinfo stripe.set_app_info("dj-stripe", version=__version__, url="https://github.com/dj-stripe/dj-stripe")
def _init_api(self): stripe.api_version = '2018-02-28' stripe.set_app_info("pretix", version=__version__, url="https://pretix.eu")
Stripe Recipe. Python 3.6 or newer required. """ import stripe import json import os from flask import Flask, render_template, jsonify, request, send_from_directory from dotenv import load_dotenv, find_dotenv # Setup Stripe python client library load_dotenv(find_dotenv()) # For sample support and debugging, not required for production: stripe.set_app_info( 'stripe-samples/saving-card-without-payment', version='0.0.1', url='https://github.com/stripe-samples/saving-card-without-payment') stripe.api_version = '2020-08-27' stripe.api_key = os.getenv('STRIPE_SECRET_KEY') static_dir = str( os.path.abspath(os.path.join(__file__, "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_setup_intent_page():
def payment_post_save(sender, instance, created, *args, **kwargs): """ Create Reserve """ if instance.request: # Testing if (instance.platform == instance.TESTING) and \ (instance.provider == instance.TEST): instance.response = instance.request if instance.request.get('amount') and \ instance.request.get('currency'): if Currency.objects.filter( label=instance.response['currency'].upper()).exists(): currency = Currency.objects.get( label=instance.response['currency'].upper()) amount = instance.request['amount'] purchase = Decimal(amount) * currency.in_hours() Reserve.objects.create( payment=instance, user=instance.owner, hours=purchase, hour_price=currency.hour_price(), currency_price=currency.currency_price(), currency=currency, amount=Decimal(amount), topic=instance.topic, is_test=True) # Stripe if (instance.platform == instance.STRIPE) and \ (instance.provider == instance.CARD): if settings.STRIPE_LIVE_MODE == 'True': stripe.api_key = settings.STRIPE_LIVE_SECRET_KEY IS_TEST = False else: stripe.api_key = settings.STRIPE_TEST_SECRET_KEY IS_TEST = True client = stripe.http_client.RequestsClient() stripe.set_app_info(settings.OWNER_ORGANIZATION_NAME, version="latest", url=settings.ALLOWED_HOSTS) if 'card' in instance.request.keys(): try: token = stripe.Token.create( card=instance.request['card'], ) except: class dummy: pass token = dummy() token.id = 'not-retrieved' instance.request.update({'card': token.id}) # Cause it won't get updated otherwise after save: Payment.objects.filter(pk=instance.pk).update( request=instance.request) currency_label = instance.request.get('currency') currency_amount = instance.request.get('amount') # Assume that amount is sent in dollars, and we need to convert it to cents. if currency_label.upper() in Currency.objects.all().values_list( 'label', flat=True): currency_amount = int(float(currency_amount) * 100.) instance.request.update({'amount': currency_amount}) resp = stripe.Charge.create(**instance.request) try: #instance.paid = resp.paid Payment.objects.filter(pk=instance.pk).update(paid=resp.paid) except: # In this case, it is left with default value (unknown) pass #TODO: move to pre-save. #instance.response = resp.to_dict() Payment.objects.filter(pk=instance.pk).update( response=resp.to_dict()) # Assume that amount is in cents, and we need to convert it to dollars. if Currency.objects.filter(label=resp.currency.upper()).exists(): amount = resp.amount / 100. # Compute the amount of hours bought currency = Currency.objects.get(label=resp.currency.upper()) purchase = Decimal(amount) * currency.in_hours() Reserve.objects.create( payment=instance, user=instance.owner, hours=purchase, hour_price=currency.hour_price(), currency_price=currency.currency_price(), currency=currency, amount=Decimal(amount), topic=instance.topic, is_test=IS_TEST) else: pass
Stripe Recipe. Python 3.6 or newer required. """ import stripe import json import os from flask import Flask, render_template, jsonify, request from dotenv import load_dotenv, find_dotenv # Setup Stripe python client library load_dotenv(find_dotenv()) # For sample support and debugging, not required for production: stripe.set_app_info( 'stripe-samples/subscription-use-cases/per-seat-subscriptions', version='0.0.1', url='https://github.com/stripe-samples/subscription-use-cases/per-seat-subscriptions') stripe.api_version = '2020-08-27' stripe.api_key = os.getenv('STRIPE_SECRET_KEY') static_dir = str(os.path.abspath(os.path.join( __file__, "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_index(): return render_template('index.html')
""" .. module:: djstripe. :synopsis: dj-stripe - Django + Stripe Made Easy """ from __future__ import absolute_import, division, print_function, unicode_literals import pkg_resources import stripe from . import checks # noqa: Register the checks __version__ = pkg_resources.require("dj-stripe")[0].version # Set app info # https://stripe.com/docs/building-plugins#setappinfo stripe.set_app_info( "dj-stripe", version=__version__, url="https://github.com/dj-stripe/dj-stripe" )
from flask import Flask, render_template, jsonify, request, send_from_directory from dotenv import load_dotenv, find_dotenv # Setup Stripe python client library. load_dotenv(find_dotenv()) # Ensure environment variables are set. price = os.getenv('PRICE') if price is None or price == 'price_12345' or price == '': print('You must set a Price ID in .env. Please see the README.') exit(0) # For sample support and debugging, not required for production: stripe.set_app_info( 'stripe-samples/checkout-one-time-payments', version='0.0.1', url='https://github.com/stripe-samples/checkout-one-time-payments') stripe.api_version = '2020-08-27' stripe.api_key = os.getenv('STRIPE_SECRET_KEY') static_dir = str( os.path.abspath(os.path.join(__file__, "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_example():
#! /usr/bin/env python3.6 import stripe import json import os from flask import Flask, render_template, jsonify, request, send_from_directory from dotenv import load_dotenv, find_dotenv load_dotenv(find_dotenv()) # For sample support and debugging, not required for production: stripe.set_app_info( 'stripe-samples/accept-a-payment/custom-payment-flow', version='0.0.1', url='https://github.com/stripe-samples') stripe.api_version = '2020-08-27' stripe.api_key = os.getenv('STRIPE_SECRET_KEY') static_dir = str(os.path.abspath(os.path.join(__file__ , "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_root(): return render_template('index.html') @app.route('/config', methods=['GET']) def get_config(): return jsonify({'publishableKey': os.getenv('STRIPE_PUBLISHABLE_KEY')})
Stripe Sample. Python 3.6 or newer required. """ import stripe import json import os from flask import Flask, render_template, jsonify, request, send_from_directory, redirect from dotenv import load_dotenv, find_dotenv # Setup Stripe python client library load_dotenv(find_dotenv()) # For sample support and debugging, not required for production: stripe.set_app_info( 'stripe-samples/checkout-single-subscription', version='0.0.1', url='https://github.com/stripe-samples/checkout-single-subscription') stripe.api_version = '2020-08-27' stripe.api_key = os.getenv('STRIPE_SECRET_KEY') static_dir = str(os.path.abspath(os.path.join( __file__, "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_example(): return render_template('index.html')
from flask import Flask, render_template, jsonify, request, send_from_directory from dotenv import load_dotenv, find_dotenv # Setup Stripe python client library. load_dotenv(find_dotenv()) # Ensure environment variables are set. price = os.getenv('PRICE') if price is None or price == 'price_12345' or price == '': print('You must set a Price ID in .env. Please see the README.') exit(0) # For sample support and debugging, not required for production: stripe.set_app_info('stripe-samples/accept-a-payment/prebuilt-checkout-page', version='0.0.1', url='https://github.com/stripe-samples') stripe.api_key = os.getenv('STRIPE_SECRET_KEY') stripe.api_version = '2020-08-27' static_dir = str( os.path.abspath(os.path.join(__file__, "..", os.getenv("STATIC_DIR")))) app = Flask(__name__, static_folder=static_dir, static_url_path="", template_folder=static_dir) @app.route('/', methods=['GET']) def get_example():