Class: SecupayRuby::Payment
- Inherits:
-
Object
- Object
- SecupayRuby::Payment
- Defined in:
- lib/secupay_ruby/payment.rb
Defined Under Namespace
Modules: Types
Constant Summary collapse
- INIT_FIELDS =
{ hash: "hash", iframe_url: "iframe_url", purpose: "purpose", payment_data: "payment_data" }
- STATUS_FIELDS =
{ payment_status: "payment_status", status: "status", created_at: "created", demo: "demo", amount: "amount", payment_details: "opt", transaction_id: "trans_id" }
Instance Attribute Summary collapse
-
#amount ⇒ Object
readonly
Returns the value of attribute amount.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#demo ⇒ Object
readonly
Returns the value of attribute demo.
-
#payment_type ⇒ Object
readonly
Returns the value of attribute payment_type.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Class Method Summary collapse
Instance Method Summary collapse
- #cancel ⇒ Object
- #capture ⇒ Object
- #hash? ⇒ Boolean
- #init(amount:, payment_type:, demo: 1) ⇒ Object
-
#initialize(api_key: SecupayRuby::ApiKey::MasterKey.new, hash: nil) ⇒ Payment
constructor
A new instance of Payment.
- #load_status ⇒ Object
Constructor Details
#initialize(api_key: SecupayRuby::ApiKey::MasterKey.new, hash: nil) ⇒ Payment
Returns a new instance of Payment.
29 30 31 32 |
# File 'lib/secupay_ruby/payment.rb', line 29 def initialize(api_key: SecupayRuby::ApiKey::MasterKey.new, hash: nil) @api_key = api_key @hash = hash end |
Instance Attribute Details
#amount ⇒ Object (readonly)
Returns the value of attribute amount.
8 9 10 |
# File 'lib/secupay_ruby/payment.rb', line 8 def amount @amount end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
8 9 10 |
# File 'lib/secupay_ruby/payment.rb', line 8 def api_key @api_key end |
#demo ⇒ Object (readonly)
Returns the value of attribute demo.
8 9 10 |
# File 'lib/secupay_ruby/payment.rb', line 8 def demo @demo end |
#payment_type ⇒ Object (readonly)
Returns the value of attribute payment_type.
8 9 10 |
# File 'lib/secupay_ruby/payment.rb', line 8 def payment_type @payment_type end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
8 9 10 |
# File 'lib/secupay_ruby/payment.rb', line 8 def response @response end |
Class Method Details
.get_types(api_key: SecupayRuby::ApiKey::MasterKey.new) ⇒ Object
93 94 95 96 97 |
# File 'lib/secupay_ruby/payment.rb', line 93 def get_types(api_key: SecupayRuby::ApiKey::MasterKey.new) response = SecupayRuby::Requests::GetTypes.post(api_key: api_key) response.data end |
Instance Method Details
#cancel ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/secupay_ruby/payment.rb', line 83 def cancel raise_if_not_initiated @response = nil @response = SecupayRuby::Requests::Cancel.post(api_key: api_key, payment: self) end |
#capture ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/secupay_ruby/payment.rb', line 74 def capture raise_if_not_initiated @response = nil @response = SecupayRuby::Requests::Capture.post(api_key: api_key, payment: self) end |
#hash? ⇒ Boolean
34 35 36 |
# File 'lib/secupay_ruby/payment.rb', line 34 def hash? !hash.nil? end |
#init(amount:, payment_type:, demo: 1) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/secupay_ruby/payment.rb', line 38 def init(amount:, payment_type:, demo: 1) @response = nil @amount = amount @payment_type = payment_type @demo = demo raise_if_payment_not_initiated raise_if_payment_type_invalid params = { amount: amount, demo: demo, payment_type: payment_type } @response = SecupayRuby::Requests::Init.post(api_key: api_key, payment: self, body: params) extract_response_params(INIT_FIELDS) end |
#load_status ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/secupay_ruby/payment.rb', line 61 def load_status raise_if_not_initiated @response = nil params = { hash: hash } @response = SecupayRuby::Requests::Status.post(api_key: api_key, payment: self, body: params) extract_response_params(STATUS_FIELDS) end |