Class: WebPay::Charge

Inherits:
ApiResource show all
Defined in:
lib/webpay/charge.rb

Instance Method Summary collapse

Methods inherited from ApiResource

#initialize

Constructor Details

This class inherits a constructor from WebPay::ApiResource

Instance Method Details

#all(params = {}) ⇒ ChargeResponseList

List charges filtered by params.

Parameters:

Returns:



48
49
50
51
52
# File 'lib/webpay/charge.rb', line 48

def all(params = {})
  req = WebPay::ChargeListRequest.create(params)
  raw_response = @client._request(:get, 'charges', req)
  WebPay::ChargeResponseList.new(raw_response)
end

#capture(params = {}) ⇒ ChargeResponse

Capture a not captured charge specified by charge id.

Parameters:

Returns:



38
39
40
41
42
# File 'lib/webpay/charge.rb', line 38

def capture(params = {})
  req = WebPay::ChargeRequestWithAmount.create(params)
  raw_response = @client._request(:post, 'charges' + '/' + req.id.to_s + '/' + 'capture', req)
  WebPay::ChargeResponse.new(raw_response)
end

#create(params = {}) ⇒ ChargeResponse

Create a charge object with given parameters. In live mode, this issues a transaction.

Parameters:

Returns:



7
8
9
10
11
# File 'lib/webpay/charge.rb', line 7

def create(params = {})
  req = WebPay::ChargeRequestCreate.create(params)
  raw_response = @client._request(:post, 'charges', req)
  WebPay::ChargeResponse.new(raw_response)
end

#refund(params = {}) ⇒ ChargeResponse

Refund a paid charge specified by charge id. Optional argument amount is to refund partially.

Parameters:

Returns:



28
29
30
31
32
# File 'lib/webpay/charge.rb', line 28

def refund(params = {})
  req = WebPay::ChargeRequestRefund.create(params)
  raw_response = @client._request(:post, 'charges' + '/' + req.id.to_s + '/' + 'refund', req)
  WebPay::ChargeResponse.new(raw_response)
end

#retrieve(params = {}) ⇒ ChargeResponse

Retrieve a existing charge object by charge id.

Parameters:

  • params (ChargeIdRequest|Hash) (defaults to: {})

    Parameters to API call

Returns:



17
18
19
20
21
# File 'lib/webpay/charge.rb', line 17

def retrieve(params = {})
  req = WebPay::ChargeIdRequest.create(params)
  raw_response = @client._request(:get, 'charges' + '/' + req.id.to_s, req)
  WebPay::ChargeResponse.new(raw_response)
end