module Spreedly::Subscriptions

Constants

MOCK
VERSION

Public Class Methods

configure(site_name, token) click to toggle source

Call this before you start using the API to set things up.

# File lib/spreedly/subscriptions.rb, line 42
def self.configure(site_name, token)
  base_uri "https://subs.pinpayments.com/api/v4/#{site_name}"
  basic_auth token, 'X'
  @site_name = site_name
end
edit_subscriber_url(token, return_url = nil) click to toggle source

Generates an edit subscriber for the given subscriber token. The token is returned with the subscriber info (i.e. by Subscriber.find).

# File lib/spreedly/subscriptions/common.rb, line 38
def self.edit_subscriber_url(token, return_url = nil)
  "https://subs.pinpayments.com/#{site_name}/subscriber_accounts/#{token}" +
  if return_url
    "?return_url=#{URI.escape(return_url)}"
  else
    ''
  end
end
site_name() click to toggle source
# File lib/spreedly/subscriptions/mock.rb, line 13
def self.site_name
  @site_name
end
subscribe_url(id, plan, options={}) click to toggle source

Generates a subscribe url for the given user id and plan. Options:

:screen_name => a screen name for the user (shows up in the admin UI)
:email => pre-populate the email field
:first_name => pre-populate the first name field
:last_name => pre-populate the last name field
# File lib/spreedly/subscriptions/common.rb, line 20
def self.subscribe_url(id, plan, options={})
  %w(screen_name email first_name last_name return_url).each do |option|
    options[option.to_sym] &&= URI.escape(options[option.to_sym])
  end

  screen_name = options.delete(:screen_name)
  params = %w(email first_name last_name return_url).select{|e| options[e.to_sym]}.collect{|e| "#{e}=#{options[e.to_sym]}"}.join('&')

  url = "https://subs.pinpayments.com/#{site_name}/subscribers/#{id}/subscribe/#{plan}"
  url << "/#{screen_name}" if screen_name
  url << '?' << params unless params == ''

  url
end