Skip to content

Instantly share code, notes, and snippets.

@mbeale
mbeale / gist:5207507
Created March 20, 2013 19:08
Alter expiration fields Recurly.js
Recurly.buildSubscriptionForm({
/* other options */
afterInject: function(){
$('.month select').val(2); //month
$('.year select').val(2016); //year
},
});
@mbeale
mbeale / gist:8569047
Last active January 4, 2016 04:29
Ruby fetch IDs EasyPost
require "easypost"
EasyPost.api_key = 'YOUR API KEY'
shipment_ids = #fetch a list of shipment ids from your end
shipment_ids.each do |id|
shipment = EasyPost::Shipment.retrieve(id)
if shipment.tracker.status == 'pre_transit'
begin
shipment.refund
@mbeale
mbeale / shippingexport.py
Last active December 31, 2015 13:09
EasyPost - Python export shipments to csv
#
# This will fetch shipments and ouput them into csv
#
# Dependencies
# python requests lib - pip install requests
# python iso8601 lib - pip install iso8601
#
# Setup
# add your API key to the code
#
@mbeale
mbeale / gist:7044836
Created October 18, 2013 17:21
Easypost webhook with sinatra
require 'easypost'
require 'sinatra'
require 'json'
post '/webhook' do
e = EasyPost::Event.new
e.receive(JSON.parse(request.body.string))
e.result.to_s
end
@mbeale
mbeale / gist:6998412
Last active December 25, 2015 15:29
Flask and Easypost handle webhooks
from flask import Flask, request
import easypost
import json
app = Flask(__name__)
@app.route("/webhooks", methods=['POST'])
def webhook():
e = easypost.Event()
e.receive(json.loads(request.form.keys()[0]))
@mbeale
mbeale / couponsubmit
Created October 4, 2013 16:16
Submit a coupon automatically
Recurly.buildSubscriptionForm({
/* other options */
subscription: {
couponCode: 'testplan'
},
distinguishContactFromBillingInfo: true,
afterInject: function(){
if($('.coupon_code').val()){
$('div.check').click();
}
@mbeale
mbeale / signature.php
Created October 3, 2013 17:33
Recurly js signature for account_code override
$signature = Recurly_js::sign(array(
'account'=>array('account_code'=>'_my_account_code'),
'subscription' => array('plan_code' => 'instant')
)
);
@mbeale
mbeale / success
Created September 27, 2013 20:17
success: function (data) {
//if the error object exits
//then ther submission was
//not sucessful
if(errors in data){
//handle the errors
} else {
// it was successful
}
},
@mbeale
mbeale / submitjs
Last active December 24, 2015 02:59
$('#submit-btn').click(function({
$.ajax({
dataType: 'jsonp',
url: 'https://(your-subdomain).recurly.com/jsonp/(your-subdomain)/subscribe',
data: {
signature: signature,
billing_info: {
first_name: 'Ned',
last_name: 'Stark',
address1: '1234 Winterfell Rd',
@mbeale
mbeale / signature
Last active December 24, 2015 02:59
<script>
var signature = "<?php echo Recurly_js::sign(array(
'account'=>array('account_code'=>'test_gbp_1234'),
'subscription' => array('plan_code' => 'instant')
)); ?>";
</script>