Skip to content

Instantly share code, notes, and snippets.

@Austio
Created July 18, 2014 16:46
Show Gist options
  • Save Austio/2bba43af6e49578883ae to your computer and use it in GitHub Desktop.
Save Austio/2bba43af6e49578883ae to your computer and use it in GitHub Desktop.
def self.create_subscription(recurrance, recurly_token, paysysid)
response = Recurly::Subscription.create! plan_code: "premium-#{recurrance}",
account: {
account_code: paysysid,
billing_info: { token_id: recurly_token }
}
if response.is_a? Recurly::Subscription
return paysysid if response.state == "active"
end
#activated_at, state, valid
return "Error Processing: #{response.try(:errors).try(:first)}"
rescue Recurly::Resource::Invalid, Recurly::API::ResponseError => e
return "Error Processing: #{e.try(:message)}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment