Skip to content

Commit

Permalink
Merge pull request #83 from conekta/feature/allow-amount-in-capture-c…
Browse files Browse the repository at this point in the history
…harge

Allow capture amount to be set
  • Loading branch information
luiscarlos-gonzalez authored Dec 21, 2017
2 parents b7c1993 + 9fbb00b commit e6a425c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/conekta/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ class Charge < Resource
:exchange_rate, :foreign_currency, :amount_in_foreign_currency,
:checkout_id, :checkout_order_count

def capture
custom_action(:post, 'capture')
# Usage: charge_reference.capture(2000)
def capture(params={})
params = { 'amount' => (params || self.amount) }
custom_action(:post, 'capture', params)
end

def refund(params=nil)
Expand Down
16 changes: 16 additions & 0 deletions spec/conekta/1.0.0/charge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,20 @@
)
end
end

context 'capturing charges' do
it 'captures an existing charge' do
amount_before_capture = 2000
amount_after_capture = 1000
capture = { capture: false }
transaction = Conekta::Charge.create(
payment_method.merge(card).merge(capture)
)
expect(transaction.status).to eq('pre_authorized')
expect(transaction.amount).to be == amount_before_capture
transaction.capture(1000)
expect(transaction.amount).to be == amount_after_capture
expect(transaction.status).to eq("paid")
end
end
end

0 comments on commit e6a425c

Please sign in to comment.