Class: Paymongo::Gateway
- Inherits:
-
Object
- Object
- Paymongo::Gateway
- Defined in:
- lib/paymongo/gateway.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #charge_card(token:, amount:, currency:, description: '', statement_descriptor: '') ⇒ Object
-
#initialize(config) ⇒ Gateway
constructor
A new instance of Gateway.
- #transaction ⇒ Object
Constructor Details
#initialize(config) ⇒ Gateway
Returns a new instance of Gateway.
5 6 7 8 9 10 11 12 13 |
# File 'lib/paymongo/gateway.rb', line 5 def initialize(config) if config.is_a?(Hash) @config = Configuration.new config elsif config.is_a?(Paymongo::Configuration) @config = config else raise ArgumentError, 'config is an invalid type' end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/paymongo/gateway.rb', line 3 def config @config end |
Instance Method Details
#charge_card(token:, amount:, currency:, description: '', statement_descriptor: '') ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/paymongo/gateway.rb', line 15 def charge_card( token:, amount:, currency:, description: '', statement_descriptor: '' ) header = { 'Content-Type': 'application/json' } payment_params = { data: { attributes: { amount: amount, currency: currency, description: description, statement_descriptor: statement_descriptor, source: { id: token, type: 'token' } } } }.to_json uri = URI.parse('https://api.paymongo.com/v1/payments') https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true req = Net::HTTP::Post.new(uri.path, header) req.basic_auth(config.secret_key, '') req.body = payment_params https.request(req) end |
#transaction ⇒ Object
40 41 42 |
# File 'lib/paymongo/gateway.rb', line 40 def transaction TransactionGateway.new(self) end |