Class: SecupayRuby::Payment

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#amountObject (readonly)

Returns the value of attribute amount.



8
9
10
# File 'lib/secupay_ruby/payment.rb', line 8

def amount
  @amount
end

#api_keyObject (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

#demoObject (readonly)

Returns the value of attribute demo.



8
9
10
# File 'lib/secupay_ruby/payment.rb', line 8

def demo
  @demo
end

#payment_typeObject (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

#responseObject (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

#cancelObject



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

#captureObject



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/secupay_ruby/payment.rb', line 34

def hash?
  !hash.nil?
end

#init(amount:, payment_type:, demo: 0) ⇒ 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: 0)
  @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_statusObject



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