Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resource for External Payments #128

Merged
merged 1 commit into from
May 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions examples/payments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
$: << File.expand_path(File.dirname(__FILE__) + '/../lib')

require "chargify_api_ares"

Chargify.configure do |c|
c.subdomain = ENV['CHARGIFY_SUBDOMAIN']
c.api_key = ENV['CHARGIFY_API_KEY']
end

# Find a Chargify Subscription
sub = Chargify::Subscription.find_by_customer_reference 'abc-123-def-456'

# Record an external payment on the Chargify Subscription
pmt = sub.payment(
amount_in_cents: 2500,
memo: "Pre-payment for..."
)

# Or, create the external payment directly:
pmt = Chargify::Payment.create(
subscription_id: sub.id,
amount_in_cents: 2500,
memo: "Pre-payment for..."
)
1 change: 1 addition & 0 deletions lib/chargify_api_ares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require 'chargify_api_ares/resources/customer'
require 'chargify_api_ares/resources/event'
require 'chargify_api_ares/resources/migration'
require 'chargify_api_ares/resources/payment'
require 'chargify_api_ares/resources/payment_profile'
require 'chargify_api_ares/resources/product'
require 'chargify_api_ares/resources/product_family'
Expand Down
7 changes: 7 additions & 0 deletions lib/chargify_api_ares/resources/payment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Chargify
class Payment < Base
include ResponseHelper

self.prefix = '/subscriptions/:subscription_id/'
end
end
8 changes: 8 additions & 0 deletions lib/chargify_api_ares/resources/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ def charge(attrs = {})
Chargify::Charge.create(attrs.merge(:subscription_id => self.id))
end

# Record an external payment on an existing subscription.
# This DOES NOT charge the customer's credit card.
# For more information, please see the API docs available
# at: https://docs.chargify.com/api-payments
def payment(attrs = {})
Chargify::Payment.create(attrs.merge(:subscription_id => self.id))
end

def credit(attrs = {})
attrs, options = extract_uniqueness_token(attrs)
process_capturing_errors do
Expand Down