Class: Paynl::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/paynl/transaction.rb

Instance Method Summary collapse

Instance Method Details

#getTransaction(transactionId) ⇒ Object



125
126
127
128
129
# File 'lib/paynl/transaction.rb', line 125

def getTransaction(transactionId)
  api = Paynl::Api::TransactionInfo.new
  api.setTransactionId(transactionId)
  return api.doRequest
end

#refund(transactionId, amount = nil, description = nil) ⇒ Object



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/paynl/transaction.rb', line 131

def refund(transactionId, amount = nil, description = nil)
  api = Paynl::Api::TransactionRefund.new
  api.setTransactionId(transactionId)
  unless amount.nil?
    api.setAmount(amount)
  end
  unless description.nil?
    api.setDescription(description)
  end
  return api.doRequest
end

#start(options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/paynl/transaction.rb', line 3

def start(options)
  enduser = Hash.new

  api = Paynl::Api::StartTransaction.new
  unless (options['amount'].nil?)
    api.setAmount(options['amount'].round(2) * 100)
  end

  unless (options['currency'].nil?)
    api.setCurrency(options['currency'])
  end

  unless (options['returnUrl'].nil?)
    api.setFinishUrl(options['returnUrl'])
  end

  unless (options['exchangeUrl'].nil?)
    api.setExchangeUrl(options['exchangeUrl'])
  end

  unless (options['paymentMethod'].nil?)
    api.setPaymentOptionId(options['paymentMethod'])
  end

  unless (options['bank'].nil?)
    api.setPaymentOptionSubId(options['bank'])
  end

  unless (options['description'].nil?)
    api.setDescription(options['description'])
  end

  unless (options['testMode'].nil?)
    if options['testMode'] == true or options['testMode'] == 'true'
      api.setTestMode(true)
    end
  end

  unless (options['ipaddress'].nil?)
    api.setIpAddress(options['ipaddress'])
  end

  unless (options['extra1']).nil?
    api.setExtra1(options['extra1'])
  end

  unless (options['extra2'].nil?)
    api.setExtra2(options['extra2'])
  end

  unless (options['extra3'].nil?)
    api.setExtra3(options['extra3'])
  end

  unless (options['products'].nil?)
    options['products'].each_with_index {
        |product, index|
      taxClass = Paynl::Helper::calculateTaxClass(product[1]['price'], product[1]['tax'])
      api.addProduct(product[1]['id'], product[1]['name'], (product[1]['price'].round * 100), product[1]['qty'], taxClass)
    }
  end

  unless (options['enduser'].nil?)
    enduser = options['enduser'].to_hash
  end

  unless (options['language'].nil?)
    enduser['language'] = options['language']
  end

  unless (options['address'].nil?)
    address = Hash.new
    unless (options['address']['streetName'].nil?)
      address.store('streetName', options['address']['streetName'])
    end
    unless (options['address']['houseNumber'].nil?)
      address.store('houseNumber', options['address']['houseNumber'])
    end
    unless (options['address']['zipCode'].nil?)
      address.store('zipCode', options['address']['zipCode'])
    end
    unless (options['address']['city'].nil?)
      address.store('city', options['address']['city'])
    end
    unless (options['address']['country'].nil?)
      address.store('country', options['address']['country'])
    end
    enduser.store('address', address)
  end

  unless (options['invoiceAddress'].nil?)
    invoiceAddress = Hash.new

    unless (options['invoiceAddress']['initials'].nil?)
      invoiceAddress.store('initials', options['invoiceAddress']['initials'])
    end
    unless (options['invoiceAddress']['lastName'].nil?)
      invoiceAddress.store('lastName', options['invoiceAddress']['lastName'])
    end

    unless (options['invoiceAddress']['streetName'].nil?)
      invoiceAddress.store('streetName', options['invoiceAddress']['streetName'])
    end
    unless (options['invoiceAddress']['houseNumber'].nil?)
      invoiceAddress.store('houseNumber', options['invoiceAddress']['houseNumber'])
    end
    unless (options['invoiceAddress']['zipCode'].nil?)
      invoiceAddress.store('zipCode', options['invoiceAddress']['zipCode'])
    end
    unless (options['invoiceAddress']['city'].nil?)
      invoiceAddress.store('city', options['invoiceAddress']['city'])
    end
    unless (options['invoiceAddress']['country'].nil?)
      invoiceAddress.store('country', options['invoiceAddress']['country'])
    end
    enduser.store('invoiceAddress', invoiceAddress)
  end

  api.setEnduser(enduser)
  return api.doRequest
end