Fix: Remove keys etc. for public demo repo.
This commit is contained in:
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 14 KiB |
Binary file not shown.
@@ -1,88 +0,0 @@
|
||||
from abc import abstractmethod
|
||||
import types
|
||||
|
||||
class AbstractBaseClass:
|
||||
def __init_subclass__(cls, **kwargs):
|
||||
super().__init_subclass__(**kwargs)
|
||||
for name, value in vars(AbstractBaseClass).items():
|
||||
if getattr(value, "__isabstractmethod__", False):
|
||||
if name not in cls.__dict__:
|
||||
raise TypeError(f"Can't instantiate class {cls.__name__} "
|
||||
f"without implementation of abstract method {name}")
|
||||
subclass_value = cls.__dict__[name]
|
||||
if (isinstance(value, (staticmethod, classmethod)) and
|
||||
not isinstance(subclass_value, type(value))):
|
||||
raise TypeError(f"Abstract {type(value).__name__} {name} in {cls.__name__} "
|
||||
f"must be implemented as a {type(value).__name__}")
|
||||
|
||||
def __new__(cls, *args, **kwargs):
|
||||
if cls is AbstractBaseClass:
|
||||
raise TypeError("Can't instantiate abstract class AbstractBaseClass directly")
|
||||
return super().__new__(cls)
|
||||
|
||||
@abstractmethod
|
||||
def instance_method(self):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
@abstractmethod
|
||||
def class_method(cls):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
@abstractmethod
|
||||
def static_method():
|
||||
pass
|
||||
|
||||
class ConcreteClass(AbstractBaseClass):
|
||||
def instance_method(self):
|
||||
return "Implemented instance method"
|
||||
|
||||
@classmethod
|
||||
def class_method(cls):
|
||||
return "Implemented class method"
|
||||
|
||||
@staticmethod
|
||||
def static_method():
|
||||
return "Implemented static method"
|
||||
|
||||
class IncompleteClass(AbstractBaseClass):
|
||||
def instance_method(self):
|
||||
return "Only implemented instance method"
|
||||
# class_method and static_method are not implemented
|
||||
|
||||
class IncorrectImplementationClass(AbstractBaseClass):
|
||||
def instance_method(self):
|
||||
return "Implemented instance method"
|
||||
|
||||
@classmethod
|
||||
def class_method(cls):
|
||||
return "Implemented class method"
|
||||
|
||||
def static_method(self): # This should be a static method, not an instance method
|
||||
return "Incorrectly implemented static method"
|
||||
|
||||
# Usage
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
concrete = ConcreteClass()
|
||||
print(concrete.instance_method())
|
||||
print(ConcreteClass.class_method())
|
||||
print(ConcreteClass.static_method())
|
||||
except TypeError as e:
|
||||
print(f"Error with ConcreteClass: {e}")
|
||||
|
||||
try:
|
||||
IncompleteClass()
|
||||
except TypeError as e:
|
||||
print(f"Error with IncompleteClass: {e}")
|
||||
|
||||
try:
|
||||
IncorrectImplementationClass()
|
||||
except TypeError as e:
|
||||
print(f"Error with IncorrectImplementationClass: {e}")
|
||||
|
||||
try:
|
||||
AbstractBaseClass()
|
||||
except TypeError as e:
|
||||
print(f"Error with AbstractBaseClass: {e}")
|
||||
@@ -1,124 +0,0 @@
|
||||
#! /usr/bin/env python3.6
|
||||
|
||||
"""
|
||||
server.py
|
||||
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())
|
||||
|
||||
# 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_KEY_SECRET')
|
||||
|
||||
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')
|
||||
|
||||
|
||||
@app.route('/config', methods=['GET'])
|
||||
def get_publishable_key():
|
||||
price = stripe.Price.retrieve(os.getenv('PRICE'))
|
||||
return jsonify({
|
||||
'publicKey': os.getenv('STRIPE_PUBLISHABLE_KEY'),
|
||||
'unitAmount': price['unit_amount'],
|
||||
'currency': price['currency']
|
||||
})
|
||||
|
||||
# Fetch the Checkout Session to display the JSON result on the success page
|
||||
@app.route('/checkout-session', methods=['GET'])
|
||||
def get_checkout_session():
|
||||
id = request.args.get('sessionId')
|
||||
checkout_session = stripe.checkout.Session.retrieve(id)
|
||||
return jsonify(checkout_session)
|
||||
|
||||
|
||||
@app.route('/create-checkout-session', methods=['POST'])
|
||||
def create_checkout_session():
|
||||
quantity = request.form.get('quantity', 1)
|
||||
domain_url = os.getenv('DOMAIN')
|
||||
|
||||
try:
|
||||
# Create new Checkout Session for the order
|
||||
# Other optional params include:
|
||||
# [billing_address_collection] - to display billing address details on the page
|
||||
# [customer] - if you have an existing Stripe Customer ID
|
||||
# [payment_intent_data] - lets capture the payment later
|
||||
# [customer_email] - lets you prefill the email input in the form
|
||||
# [automatic_tax] - to automatically calculate sales tax, VAT and GST in the checkout page
|
||||
# For full details see https://stripe.com/docs/api/checkout/sessions/create
|
||||
|
||||
# ?session_id={CHECKOUT_SESSION_ID} means the redirect will have the session ID set as a query param
|
||||
checkout_session = stripe.checkout.Session.create(
|
||||
success_url=domain_url + '/success.html?session_id={CHECKOUT_SESSION_ID}',
|
||||
cancel_url=domain_url + '/canceled.html',
|
||||
mode='payment',
|
||||
# automatic_tax={'enabled': True},
|
||||
line_items=[{
|
||||
'price': os.getenv('PRICE'),
|
||||
'quantity': quantity,
|
||||
}]
|
||||
)
|
||||
return redirect(checkout_session.url, code=303)
|
||||
except Exception as e:
|
||||
return jsonify(error=str(e)), 403
|
||||
|
||||
|
||||
@app.route('/webhook', methods=['POST'])
|
||||
def webhook_received():
|
||||
# You can use webhooks to receive information about asynchronous payment events.
|
||||
# For more about our webhook events check out https://stripe.com/docs/webhooks.
|
||||
webhook_secret = os.getenv('STRIPE_WEBHOOK_SECRET')
|
||||
request_data = json.loads(request.data)
|
||||
|
||||
if webhook_secret:
|
||||
# Retrieve the event by verifying the signature using the raw body and secret if webhook signing is configured.
|
||||
signature = request.headers.get('stripe-signature')
|
||||
try:
|
||||
event = stripe.Webhook.construct_event(
|
||||
payload=request.data, sig_header=signature, secret=webhook_secret)
|
||||
data = event['data']
|
||||
except Exception as e:
|
||||
return e
|
||||
# Get the type of webhook event sent - used to check the status of PaymentIntents.
|
||||
event_type = event['type']
|
||||
else:
|
||||
data = request_data['data']
|
||||
event_type = request_data['type']
|
||||
data_object = data['object']
|
||||
|
||||
print('event ' + event_type)
|
||||
|
||||
if event_type == 'checkout.session.completed':
|
||||
print('🔔 Payment succeeded!')
|
||||
|
||||
return jsonify({Model_View_Base.FLAG_STATUS: Model_View_Base.FLAG_SUCCESS})
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(port=4242, debug=True)
|
||||
@@ -1,63 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<link href="../css/copiedstyles.css" rel="stylesheet" type="text/css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="header">
|
||||
<h1>My Website</h1>
|
||||
<p>Resize the browser window to see the effect.</p>
|
||||
</div>
|
||||
|
||||
<div class="topnav">
|
||||
<a href="#">Link</a>
|
||||
<a href="#">Link</a>
|
||||
<a href="#">Link</a>
|
||||
<a href="#" style="float:right">Link</a>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="leftcolumn">
|
||||
<div class="card">
|
||||
<h2>TITLE HEADING</h2>
|
||||
<h5>Title description, Dec 7, 2017</h5>
|
||||
<div class="fakeimg" style="height:200px;">Image</div>
|
||||
<p>Some text..</p>
|
||||
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h2>TITLE HEADING</h2>
|
||||
<h5>Title description, Sep 2, 2017</h5>
|
||||
<div class="fakeimg" style="height:200px;">Image</div>
|
||||
<p>Some text..</p>
|
||||
<p>Sunt in culpa qui officia deserunt mollit anim id est laborum consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rightcolumn">
|
||||
<div class="card">
|
||||
<h2>About Me</h2>
|
||||
<div class="fakeimg" style="height:100px;">Image</div>
|
||||
<p>Some text about me in culpa qui officia deserunt mollit anim..</p>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>Popular Post</h3>
|
||||
<div class="fakeimg"><p>Image</p></div>
|
||||
<div class="fakeimg"><p>Image</p></div>
|
||||
<div class="fakeimg"><p>Image</p></div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<h3>Follow Me</h3>
|
||||
<p>Some text..</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="footer">
|
||||
<h2>Footer</h2>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
print(not None)
|
||||
Reference in New Issue
Block a user