Skip to content

Instantly share code, notes, and snippets.

const fs = require('fs');
const Storage = require('@google-cloud/storage');
const BUCKET_NAME = ''; // This would actually have the name of our bucket
const storage = new Storage({
projectId: '', // This should be your Google Cloud Project ID where you're deploying your function & have your bucket
keyFilename: './keyfile.json'
});
exports.webhook = (request, response) => {
const data = JSON.stringify(request.body, null, 2);
AutoForm.addHooks("square-payment-form", {
onSubmit: function (doc) {
submitting = true;
const template = this.template;
hidePaymentAlert();
const form = {
cardNonce: doc.nonce // Here is where we're placing our nonce
};
Meteor.subscribe("Packages", Reaction.getShopId());
const packageData = Packages.findOne({
Template.squarePaymentForm.onRendered(function () {
$(document).ready(function () {
createPaymentForm();
});
$("#submitCard").on("click", function () {
paymentForm.requestCardNonce();
});
});
$.getScript("https://js.squareup.com/v2/paymentform").done(function () {
paymentForm = new SqPaymentForm({
// Setup your SqPaymentForm object, see https://docs.connect.squareup.com/payments/sqpaymentform/sqpaymentform-setup
// for more details
});
// We're manually building the form here, since the page is already loaded and won't trigger the event SqPaymentForm
// is expecting
paymentForm.build();
});
cardNonceResponseReceived: function(errors, nonce, cardData) {
if (errors) {
// Log errors from nonce generation to the Javascript console
console.log("Encountered errors:");
errors.forEach(function(error) {
console.log(" " + error.message);
});
return;
}
console.log(cardData);
<script type="text/javascript" src="https://js.squareup.com/v2/paymentform">
</script>
@mootrichard
mootrichard / addressValidation.js
Created June 20, 2017 17:22
4 Ways to Improve Post-Purchase Experience
const shippo = require('shippo')('YOUR_SHIPPO_API_KEY');
let addressObject = {
name: "Shawn Ippotle",
company: "Shippo",
street1: "218 Claytona St.",
city: "San Francisco",
state: "CA",
zip: "94117",
country: "US",
@mootrichard
mootrichard / Rest API Planning.postman_collection.json
Created May 1, 2017 06:14
Rest API Planning Test Collection
{
"variables": [],
"info": {
"name": "Rest API Planning",
"_postman_id": "4b9b4065-d319-6f32-bae2-2dd4e0f33d0d",
"description": "",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
@mootrichard
mootrichard / example.js
Created April 24, 2017 18:30
Example International Rates Quote
const shippo = require('shippo')('YOUR_SHIPPO_TOKEN');
var customsItem = {
"description":"T-Shirt",
"quantity":20,
"net_weight":"1",
"mass_unit":"lb",
"value_amount":"200",
"value_currency":"USD",
"origin_country":"US",
@mootrichard
mootrichard / example_invalid_response.json
Last active April 14, 2017 17:19
An example of posting to Shippo's webhook using Node.JS
{
"carrier": "ups",
"tracking_number": "92748931507953573000007541",
"address_from": null,
"address_to": null,
"eta": null,
"servicelevel": {
"token": null,
"name": null
},