Skip to content

Instantly share code, notes, and snippets.

Alex Reichert reichert621

Block or report user

Report or block reichert621

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View styled.jsx
// import ...
import './App.css'; // Import our new CSS
const STRIPE_API_KEY = 'pk_test_...';
const createCharge = token => {
// ...
};
const Form = props => {
View app.css
@import url('https://fonts.googleapis.com/css?family=Open+Sans:300,400,500');
* {
box-sizing: border-box;
}
html,
body {
font-family: 'Open Sans', 'Helvetica Neue', Arial, san-serif;
line-height: 1.15;
View index.html
<!DOCTYPE html>
<html lang="en">
<head>
<!-- ... -->
<!-- Add this script tag within the <head> tags! -->
<script src="https://js.stripe.com/v3"></script>
</head>
<body>
View orders.js
const express = require('express');
const bodyParser = require('body-parser');
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
const createOrder = (skuId, { email, name, address }) => {
View charges.js
// Load environment variables from our `.env` file
require('dotenv').config();
const path = require('path');
const express = require('express');
// Make sure your STRIPE_SECRET_KEY exists as an environment variable!
// This should look something like `sk_test_xxxxxxxxxxxxxxxxxxxxxxxxx`
// and can be found at https://dashboard.stripe.com/test/apikeys
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);
View legacy-checkout.jsx
import request from 'superagent';
import React from 'react';
import StripeCheckout from 'react-stripe-checkout';
// Replace with your public key (https://dashboard.stripe.com/test/apikeys)
const STRIPE_API_KEY = 'pk_test_xxx';
const createOrder = (skuId, customer) => {
const { email, name, address } = customer;
View checkout.jsx
import React from 'react';
import { StripeProvider, Elements, injectStripe } from 'react-stripe-elements';
// Replace with your public key (https://dashboard.stripe.com/test/apikeys)
const STRIPE_API_KEY = 'pk_test_xxx';
const Checkout = props => {
const handleCheckout = () => {
props.stripe.redirectToCheckout({
items: [{ sku: props.skuId, quantity: 1 }],
View elements.jsx
import request from 'superagent';
import React from 'react';
import ReactDOM from 'react-dom';
import {
StripeProvider,
Elements,
CardElement,
injectStripe
} from 'react-stripe-elements';
View validations-2.js
const getValidators = () => {
return [
{
field: 'name',
validations: [
[isInputPresent, 'Name is required'],
[isValidName, 'Invalid name']
]
},
View validations-1.js
const moment = require('moment');
const isInputPresent = input => {
return input && typeof input === 'string' && input.trim().length > 0;
};
const isValidEmail = email => {
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return regex.test(String(email).toLowerCase());
You can’t perform that action at this time.