Class: Postfinancecheckout::Transaction
- Inherits:
-
Object
- Object
- Postfinancecheckout::Transaction
- Defined in:
- lib/postfinancecheckout/transaction.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Class Method Summary collapse
- .create(amount: 0, email: '', address: {}, order_number: '') ⇒ Object
- .find(transaction_id) ⇒ Object
Instance Method Summary collapse
-
#initialize(amount: 0, email: '', address: {}, order_number: '', id: nil, success_url: '', failure_url: '') ⇒ Transaction
constructor
A new instance of Transaction.
- #payment_url ⇒ Object
- #save ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(amount: 0, email: '', address: {}, order_number: '', id: nil, success_url: '', failure_url: '') ⇒ Transaction
Returns a new instance of Transaction.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/postfinancecheckout/transaction.rb', line 7 def initialize(amount: 0, email: '', address: {}, order_number: '', id: nil, success_url: '', failure_url: '') @amount = amount @email = email @address = address @order_number = order_number @id = id @success_url = success_url @failure_url = failure_url PostFinanceCheckout.configure do |config| config.user_id = app_user_id config.authentication_key = app_user_key end end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
5 6 7 |
# File 'lib/postfinancecheckout/transaction.rb', line 5 def id @id end |
Class Method Details
.create(amount: 0, email: '', address: {}, order_number: '') ⇒ Object
40 41 42 43 44 |
# File 'lib/postfinancecheckout/transaction.rb', line 40 def self.create(amount: 0, email: '', address: {}, order_number: '') transaction = self.new(amount: amount, email: email, address: address, order_number: order_number) transaction.save transaction end |
.find(transaction_id) ⇒ Object
46 47 48 49 |
# File 'lib/postfinancecheckout/transaction.rb', line 46 def self.find(transaction_id) transaction = self.new(amount: nil, email: nil, address: {}, order_number: nil, id: transaction_id) transaction end |
Instance Method Details
#payment_url ⇒ Object
51 52 53 54 |
# File 'lib/postfinancecheckout/transaction.rb', line 51 def payment_url ensure_id! transaction_payment_page_service.payment_page_url(space_id, @id) end |
#save ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/postfinancecheckout/transaction.rb', line 22 def save existing = transaction_service.search(space_id, { filter: { fieldName: "merchantReference", operator: "EQUALS", type: "LEAF", value: "order-#{@order_number}" } }) if existing.any? @id = existing.first.id else tx = transaction_service.create(space_id, transaction_object) @id = tx.id end self end |
#status ⇒ Object
56 57 58 59 60 |
# File 'lib/postfinancecheckout/transaction.rb', line 56 def status ensure_id! transaction = transaction_service.read(space_id, @id) transaction.state end |