Skip to content

Instantly share code, notes, and snippets.

View mmeo's full-sized avatar

Matthew Meo mmeo

View GitHub Profile
{
"this": "that"
}
'use strict'
//requires crypto
const crypto = require("crypto")
//site shared key (find this value when clicking 'edit' on your Site)
var shared_key = "shared_key_here"
//the square bracketed webhook body (eg: id=437192735&event=signup_success&payload[subscription][id]=1...etc...)
//do not use a JSON body
//This is a small script to create a call to action button on a Chargify receipt page,
//where the link has a dymanic subdomain, based on a custom field value.
//This script is meant solely as a *starting point*. You can edit the script as needed.
//define the subdomain, by reading the custom field value
var subdomain = $("body > div.wrapper > div.success-receipt > div.success-receipt__items > dl:nth-child(4) > dd").text();
//define the button and the button's link
var button = '<a href="https://' + subdomain + '.example.com"><button name="button" class="form__button form__button--primary button--block" id="call_to_action">Click to go to your subdomain</button></a>';
<?php
//replace all <variables> with the correct values. This includes your product_handle, api key, and subdomain.
$data_here = array(
"subscription" => array(
"product_handle" => "<handle_goes_here>",
"customer_attributes" => array(
"first_name" => "Bob",
"last_name" => "Smith",
@mmeo
mmeo / add-shipping.js
Last active January 3, 2018 19:08
adding shipping with Javascript
// THE SCRIPT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// THIS CODE IS PROVIDED AS A REFERENCE, AND IS PROVIDED AS-IS.
// YOU ARE RESPONSIBLE FOR ENSURING IT WORKS PROPERLY ON YOUR PAGE(S), AND YOU
So in the following example, we will:
1) change the product
2) move the current user license amount from 5 to 0
3) move the current user license amount back to 5 (but on a new component price point)
The user would click a button to change products, and the following code could run:
1. This API call changes the products on the subscription. Just pass the product_handle of the product you want to change them to.
$subdomain = '----';
$api_key = '----';
$subscription_id = '----';
$component_id = '---';
$data = array(
"allocation" => array(
"quantity" => "500"
)
);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
</head>
<body>
<form method="post" action="https://api.chargify.com/api/v2/signups">
<?php
//Chargify Direct Credentials
//modern pages RECEIPT PAGE ONLY
if ($('.public-signup-page__success').length === 1) {
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
//Replace 123456789 with your real number
fbq('init', '123456789');