paynl 0.1.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +140 -4
- data/lib/paynl/api/transaction/start_transaction.rb +1 -1
- data/lib/paynl/helper.rb +16 -4
- data/lib/paynl/version.rb +1 -1
- data/paynl.gemspec +0 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cefd0030debec27da0ed3b2b88b0f3c9ae94a4b9
|
4
|
+
data.tar.gz: 9a2fd0ccbe739aabeb9cf80c45e704c72911312b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 47aad5fa655a8e502c277149a81a42b6521976a73596a9b468ff94420a81eac1a169bda4f52654921ea88a38677f4d98b12dd13cfde1da9630166bfb3b4a260d
|
7
|
+
data.tar.gz: cd32b835f675913318ddbb24e8542708751466629e1ead24994d13bf2b4b3c2a00e74caf3ff16207a1a56b4b8c9a496c41ae2c07910b9fadbaa231d410db79f6
|
data/README.md
CHANGED
@@ -30,16 +30,152 @@ Or install it yourself as:
|
|
30
30
|
|
31
31
|
## Requirements
|
32
32
|
This gem requires Ruby 1.9.2+.
|
33
|
+
We have tested this gem with Ruby 2.2.1.
|
33
34
|
|
34
35
|
## Usage
|
35
36
|
|
36
|
-
|
37
|
+
Loading the gem (after installation):
|
38
|
+
```ruby
|
39
|
+
require 'paynl'
|
40
|
+
```
|
41
|
+
|
42
|
+
Setting the configuration:
|
43
|
+
```ruby
|
44
|
+
require 'paynl'
|
45
|
+
|
46
|
+
Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
|
47
|
+
Paynl::Config::setServiceId('SL-3490-4320')
|
48
|
+
```
|
49
|
+
|
50
|
+
Getting a list of available payment methods for your site:
|
51
|
+
```ruby
|
52
|
+
require 'paynl'
|
37
53
|
|
38
|
-
|
54
|
+
Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
|
55
|
+
Paynl::Config::setServiceId('SL-3490-4320')
|
56
|
+
api = Paynl::Paymentmethods.new
|
57
|
+
options = Hash.new
|
58
|
+
puts api.getList(options)
|
59
|
+
```
|
60
|
+
|
61
|
+
Starting a transaction:
|
62
|
+
```ruby
|
63
|
+
require 'paynl'
|
64
|
+
|
65
|
+
Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
|
66
|
+
Paynl::Config::setServiceId('SL-3490-4320')
|
67
|
+
|
68
|
+
data = Paynl::Transaction.new
|
69
|
+
options = Hash.new
|
70
|
+
# Required values
|
71
|
+
options.store('amount', 6.21)
|
72
|
+
options.store('returnUrl', 'http://some.url.for.your.system.example.org/visitor-return-after-payment')
|
73
|
+
options.store('ipaddress', '127.0.0.1')
|
74
|
+
|
75
|
+
|
76
|
+
# Optional values
|
77
|
+
options.store('paymentMethod', 10)
|
78
|
+
options.store('description', 'demo payment')
|
79
|
+
options.store('testMode', true)
|
80
|
+
options.store('extra1', 'ext1')
|
81
|
+
options.store('extra2', 'ext2')
|
82
|
+
options.store('extra3', 'ext3')
|
83
|
+
options.store('language','EN')
|
84
|
+
|
85
|
+
# First product
|
86
|
+
products = Hash.new
|
87
|
+
product = Hash.new
|
88
|
+
product.store('id', '234567')
|
89
|
+
product.store('price', 1.21)
|
90
|
+
product.store('tax', 0.21)
|
91
|
+
product.store('name', 'Testproduct voor de demo tour')
|
92
|
+
product.store('qty', 1)
|
93
|
+
products.store(products.length + 1, product)
|
94
|
+
|
95
|
+
# Second product
|
96
|
+
product = Hash.new
|
97
|
+
product.store('id', '2')
|
98
|
+
product.store('price', 5.00)
|
99
|
+
product.store('tax', 0.87)
|
100
|
+
product.store('name', 'Testproduct 2 voor de demo tour')
|
101
|
+
product.store('qty', 1)
|
102
|
+
products.store(products.length + 1, product)
|
103
|
+
options.store('products', products)
|
104
|
+
|
105
|
+
# Enduser data
|
106
|
+
enduser = Hash.new
|
107
|
+
enduser.store('initials', 'T')
|
108
|
+
enduser.store('lastName', 'Test')
|
109
|
+
enduser.store('gender', 'M')
|
110
|
+
enduser.store('dob', '14-05-1999')
|
111
|
+
enduser.store('phoneNumber', '0612345678')
|
112
|
+
enduser.store('emailAddress', 'test@example.org')
|
113
|
+
options.store('enduser', enduser)
|
114
|
+
|
115
|
+
# Address data
|
116
|
+
address = Hash.new
|
117
|
+
address.store('streetName', 'Test')
|
118
|
+
address.store('houseNumber', '10')
|
119
|
+
address.store('zipCode', '1234AB')
|
120
|
+
address.store('city', 'Test')
|
121
|
+
address.store('country', 'NL')
|
122
|
+
options.store('address', address)
|
123
|
+
|
124
|
+
invoiceAddress = Hash.new
|
125
|
+
invoiceAddress.store('initials', 'IT')
|
126
|
+
invoiceAddress.store('lastName', 'ITTest')
|
127
|
+
invoiceAddress.store('streetName', 'ITest')
|
128
|
+
invoiceAddress.store('houseNumber', '15')
|
129
|
+
invoiceAddress.store('zipCode', '1234CC')
|
130
|
+
invoiceAddress.store('city', 'TTest')
|
131
|
+
invoiceAddress.store('country', 'NL')
|
132
|
+
options.store('invoiceAddress', invoiceAddress)
|
133
|
+
|
134
|
+
result = data.start(options)
|
135
|
+
|
136
|
+
# Store the transaction ID which is in
|
137
|
+
puts result['transaction']['transactionId']
|
138
|
+
|
139
|
+
# Redirect the user to the URL
|
140
|
+
puts result['transaction']['paymentURL']
|
141
|
+
```
|
39
142
|
|
40
|
-
|
143
|
+
To determine if a transaction has been paid, you can use:
|
144
|
+
```ruby
|
145
|
+
require 'paynl'
|
146
|
+
|
147
|
+
Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
|
148
|
+
Paynl::Config::setServiceId('SL-3490-4320')
|
149
|
+
|
150
|
+
data = Paynl::Transaction.new
|
151
|
+
result = data.getTransaction(transactionId)
|
152
|
+
if Paynl::Helper::transactionIsPaid(result) or Paynl::Helper::transactionIsPending(result)
|
153
|
+
# redirect user to thank you page
|
154
|
+
else
|
155
|
+
# it has not been paid yet, so redirect user back to checkout
|
156
|
+
end
|
157
|
+
```
|
41
158
|
|
42
|
-
|
159
|
+
When implementing the exchange script (where you should process the order in your backend):
|
160
|
+
```ruby
|
161
|
+
require 'paynl'
|
162
|
+
|
163
|
+
Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
|
164
|
+
Paynl::Config::setServiceId('SL-3490-4320')
|
165
|
+
|
166
|
+
data = Paynl::Transaction.new
|
167
|
+
result = data.getTransaction(transactionId)
|
168
|
+
if Paynl::Helper::transactionIsPaid(result)
|
169
|
+
# Process the payment
|
170
|
+
elsif Paynl::Helper::transactionIsCanceled(result)
|
171
|
+
# Payment canceled, restock items
|
172
|
+
end
|
173
|
+
|
174
|
+
puts 'TRUE| '
|
175
|
+
# Optionally you can send a message after TRUE|, you can view these messages in the logs.
|
176
|
+
# https://admin.pay.nl/logs/payment_state
|
177
|
+
puts 'Paid: ' + Paynl::Helper::transactionIsPaid(result).to_s
|
178
|
+
```
|
43
179
|
|
44
180
|
## Contributing
|
45
181
|
|
data/lib/paynl/helper.rb
CHANGED
@@ -44,10 +44,10 @@ module Paynl
|
|
44
44
|
|
45
45
|
def self.transactionIsPaid(transaction)
|
46
46
|
unless transaction.is_a? Hash
|
47
|
-
raise(
|
47
|
+
raise('Please give me the output of the Paynl::Transaction::getTransaction function')
|
48
48
|
end
|
49
49
|
|
50
|
-
if
|
50
|
+
if transaction['paymentDetails']['stateName'] == 'PAID'
|
51
51
|
return true
|
52
52
|
end
|
53
53
|
|
@@ -56,10 +56,22 @@ module Paynl
|
|
56
56
|
|
57
57
|
def self.transactionIsPending(transaction)
|
58
58
|
unless transaction.is_a? Hash
|
59
|
-
raise(
|
59
|
+
raise('Please give me the output of the Paynl::Transaction::getTransaction function')
|
60
60
|
end
|
61
61
|
|
62
|
-
if
|
62
|
+
if transaction['paymentDetails']['stateName'] == 'PENDING'
|
63
|
+
return true
|
64
|
+
end
|
65
|
+
|
66
|
+
return false
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.transactionIsCanceled(transaction)
|
70
|
+
unless transaction.is_a? Hash
|
71
|
+
raise('Please give me the output of the Paynl::Transaction::getTransaction function')
|
72
|
+
end
|
73
|
+
|
74
|
+
if transaction['paymentDetails']['stateName'] == 'CANCEL'
|
63
75
|
return true
|
64
76
|
end
|
65
77
|
|
data/lib/paynl/version.rb
CHANGED
data/paynl.gemspec
CHANGED
@@ -22,7 +22,6 @@ Gem::Specification.new do |spec|
|
|
22
22
|
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
23
|
# end
|
24
24
|
|
25
|
-
# Had to comment the next line to get this working correctly on Windows 10 in RubyMine
|
26
25
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
26
|
spec.bindir = "exe"
|
28
27
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|