paynl 0.1.1 → 1.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 597bdb4dd6e58b7935e11868bb68fe0cc4d4d270
4
- data.tar.gz: 157694b909a3c50486203eebe04362906fe8e904
2
+ SHA256:
3
+ metadata.gz: 4519098345b93aafef2fdca13a3db5539c1409d8c90fba79b93ec20e27e9b4a7
4
+ data.tar.gz: 206a0cf8f40ab3680af5b28f6d9a890384d2b1a064f0026af89ea2b2b8efc78d
5
5
  SHA512:
6
- metadata.gz: 1827605f64419ce0c155a09c2405f97bd5276f96e5d2bb1ab6ad14dc0ac3964f814051f19470699718055f611413442b6ef0e2d203fed9408f4c99784ae2c575
7
- data.tar.gz: be136dfc0bf3af14525a17f86ae1ce0679ca626b69a79459cc134aefbfa7a0981bd4739c6a21cd90709446546aac7741bc981980cb4f94e2ea511ea7b6e8a3fe
6
+ metadata.gz: 4a696a0a1a098a624d4c6783bc297eeb3344cfdd7f7a438e277fe2df22763779d68d2401bf89de756ccee6d763fb3bd88c8f87dfad0c0b6f2b6fe15dfcfdf8e8
7
+ data.tar.gz: cac50aea97db25bbc4ba871431153d332d97856de07a0a49d6f55c2c33c988710b778f1f6da0069046ee7461cdf3962ac400420dc96b6b10e8b8167b1d611375
@@ -0,0 +1,41 @@
1
+ image: "ruby:2.7"
2
+
3
+
4
+ before_script:
5
+ - ruby -v # Print out ruby version for debugging
6
+ - bundle install
7
+ - gem install rspec
8
+ - mkdir ~/.gem || true
9
+ - touch ~/.gem/credentials || true
10
+ - url_host=`git remote get-url origin | sed -e "s/https:\/\/gitlab-ci-token:.*@//g"`
11
+ # runner runs on a detached HEAD, checkout current branch for editing
12
+ - git reset --hard
13
+ - git clean -fd
14
+ - git checkout $CI_COMMIT_REF_NAME
15
+ - git pull origin $CI_COMMIT_REF_NAME
16
+ - |-
17
+ echo "---
18
+ :rubygems_api_key: $RUBYGEM_KEY" > ~/.gem/credentials
19
+ - chmod 600 ~/.gem/credentials
20
+
21
+ rspec:
22
+ stage: test
23
+ script:
24
+ - rspec spec
25
+
26
+ build:
27
+ stage: build
28
+ script:
29
+ - rake build
30
+
31
+ prepare_deployment:
32
+ stage: deploy
33
+ only:
34
+ - web
35
+ script:
36
+ - rake spec
37
+ - rake build
38
+ - git config --global user.email "sebastian@sebsoft.nl"
39
+ - git config --global user.name "Sebastian Berm"
40
+ - git remote set-url origin "https://$GIT_ACCESS_USER:$GIT_ACCESS_PASSWORD@${url_host}"
41
+ - rake release
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.9.3
4
- before_install: gem install bundler -v 1.11.2
3
+ - 2.5
4
+ - 2.6
5
+ - 2.7
6
+ before_install: gem install bundler
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'coveralls', require: false
4
+
3
5
  # Specify your gem's dependencies in paynl.gemspec
4
6
  gemspec
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ [![Build Status](https://travis-ci.org/paynl/ruby-sdk.svg?branch=master)](https://travis-ci.org/paynl/ruby-sdk) [![Coverage Status](https://coveralls.io/repos/github/paynl/ruby-sdk/badge.svg?branch=master)](https://coveralls.io/github/paynl/ruby-sdk?branch=master)
1
2
  # Pay.nl SDK in Ruby
2
3
 
3
4
  ---
@@ -29,17 +30,158 @@ Or install it yourself as:
29
30
  $ gem install paynl
30
31
 
31
32
  ## Requirements
32
- This gem requires Ruby 1.9.2+.
33
+ This gem requires Ruby 2.5+.
34
+ We have tested this gem with Ruby 2.5, 2.6 and 2.7.
33
35
 
34
36
  ## Usage
35
37
 
36
- TODO: Write usage instructions here
38
+ Loading the gem (after installation):
39
+ ```ruby
40
+ require 'paynl'
41
+ ```
42
+
43
+ Setting the configuration:
44
+ ```ruby
45
+ require 'paynl'
37
46
 
38
- ## Development
47
+ Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
48
+ Paynl::Config::setServiceId('SL-3490-4320')
49
+ Paynl::Config::setTokenCode('AT-code-here')
50
+ ```
39
51
 
40
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+ Getting a list of available payment methods for your site:
53
+ ```ruby
54
+ require 'paynl'
55
+
56
+ Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
57
+ Paynl::Config::setServiceId('SL-3490-4320')
58
+ Paynl::Config::setTokenCode('AT-code-here')
59
+ api = Paynl::Paymentmethods.new
60
+ options = Hash.new
61
+ puts api.getList(options)
62
+ ```
41
63
 
42
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
64
+ Starting a transaction:
65
+ ```ruby
66
+ require 'paynl'
67
+
68
+ Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
69
+ Paynl::Config::setServiceId('SL-3490-4320')
70
+ Paynl::Config::setTokenCode('AT-code-here')
71
+
72
+ data = Paynl::Transaction.new
73
+ options = Hash.new
74
+ # Required values
75
+ options.store('amount', 6.21)
76
+ options.store('returnUrl', 'http://some.url.for.your.system.example.org/visitor-return-after-payment')
77
+ options.store('ipaddress', '127.0.0.1')
78
+
79
+
80
+ # Optional values
81
+ options.store('paymentMethod', 10)
82
+ options.store('description', 'demo payment')
83
+ options.store('testMode', true)
84
+ options.store('extra1', 'ext1')
85
+ options.store('extra2', 'ext2')
86
+ options.store('extra3', 'ext3')
87
+
88
+ # First product
89
+ products = Hash.new
90
+ product = Hash.new
91
+ product.store('id', '234567')
92
+ product.store('price', 1.21)
93
+ product.store('tax', 0.21)
94
+ product.store('name', 'Testproduct voor de demo tour')
95
+ product.store('qty', 1)
96
+ products.store(products.length + 1, product)
97
+
98
+ # Second product
99
+ product = Hash.new
100
+ product.store('id', '2')
101
+ product.store('price', 5.00)
102
+ product.store('tax', 0.87)
103
+ product.store('name', 'Testproduct 2 voor de demo tour')
104
+ product.store('qty', 1)
105
+ products.store(products.length + 1, product)
106
+ options.store('products', products)
107
+
108
+ # Enduser data
109
+ enduser = Hash.new
110
+ enduser.store('initials', 'T')
111
+ enduser.store('lastName', 'Test')
112
+ enduser.store('gender', 'M')
113
+ enduser.store('dob', '14-05-1999')
114
+ enduser.store('phoneNumber', '0612345678')
115
+ enduser.store('emailAddress', 'test@example.org')
116
+ enduser.store('language','EN')
117
+ options.store('enduser', enduser)
118
+
119
+ # Address data
120
+ address = Hash.new
121
+ address.store('streetName', 'Test')
122
+ address.store('houseNumber', '10')
123
+ address.store('zipCode', '1234AB')
124
+ address.store('city', 'Test')
125
+ address.store('country', 'NL')
126
+ options.store('address', address)
127
+
128
+ invoiceAddress = Hash.new
129
+ invoiceAddress.store('initials', 'IT')
130
+ invoiceAddress.store('lastName', 'ITTest')
131
+ invoiceAddress.store('streetName', 'ITest')
132
+ invoiceAddress.store('houseNumber', '15')
133
+ invoiceAddress.store('zipCode', '1234CC')
134
+ invoiceAddress.store('city', 'TTest')
135
+ invoiceAddress.store('country', 'NL')
136
+ options.store('invoiceAddress', invoiceAddress)
137
+
138
+ result = data.start(options)
139
+
140
+ # Store the transaction ID which is in
141
+ puts result['transaction']['transactionId']
142
+
143
+ # Redirect the user to the URL
144
+ puts result['transaction']['paymentURL']
145
+ ```
146
+
147
+ To determine if a transaction has been paid, you can use:
148
+ ```ruby
149
+ require 'paynl'
150
+
151
+ Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
152
+ Paynl::Config::setServiceId('SL-3490-4320')
153
+ Paynl::Config::setTokenCode('AT-code-here')
154
+
155
+ data = Paynl::Transaction.new
156
+ result = data.getTransaction(transactionId)
157
+ if Paynl::Helper::transactionIsPaid(result) or Paynl::Helper::transactionIsPending(result)
158
+ # redirect user to thank you page
159
+ else
160
+ # it has not been paid yet, so redirect user back to checkout
161
+ end
162
+ ```
163
+
164
+ When implementing the exchange script (where you should process the order in your backend):
165
+ ```ruby
166
+ require 'paynl'
167
+
168
+ Paynl::Config::setApiToken('e41f83b246b706291ea9ad798ccfd9f0fee5e0ab')
169
+ Paynl::Config::setServiceId('SL-3490-4320')
170
+ Paynl::Config::setTokenCode('AT-code-here')
171
+
172
+ data = Paynl::Transaction.new
173
+ result = data.getTransaction(transactionId)
174
+ if Paynl::Helper::transactionIsPaid(result)
175
+ # Process the payment
176
+ elsif Paynl::Helper::transactionIsCanceled(result)
177
+ # Payment canceled, restock items
178
+ end
179
+
180
+ puts 'TRUE| '
181
+ # Optionally you can send a message after TRUE|, you can view these messages in the logs.
182
+ # https://admin.pay.nl/logs/payment_state
183
+ puts 'Paid: ' + Paynl::Helper::transactionIsPaid(result).to_s
184
+ ```
43
185
 
44
186
  ## Contributing
45
187
 
@@ -48,4 +190,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/paynl/
48
190
 
49
191
  ## License
50
192
 
51
- The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
193
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,21 +1,21 @@
1
1
  require 'yaml'
2
2
  require 'typhoeus'
3
3
  require 'json'
4
- require 'paynl/api/api'
5
- require 'paynl/error/required/serviceiderror'
6
- require 'paynl/error/required/apitokenerror'
7
- require 'paynl/error/requirederror'
8
- require 'paynl/helper'
9
- require 'paynl/version'
10
- require 'paynl/api/validate/is_pay_server_ip'
11
- require 'paynl/api/validate/get_pay_server_ips'
12
- require 'paynl/api/transaction/get_service'
13
- require 'paynl/api/transaction/start_transaction'
14
- require 'paynl/api/transaction/info'
15
- require 'paynl/api/transaction/refund'
16
- require 'paynl/api/api'
17
- require 'paynl/config'
18
- require 'paynl/transaction'
19
- require 'paynl/paymentmethods'
20
- require 'paynl'
4
+ require_relative 'paynl/api/api'
5
+ require_relative 'paynl/error/required/serviceiderror'
6
+ require_relative 'paynl/error/required/apitokenerror'
7
+ require_relative 'paynl/error/requirederror'
8
+ require_relative 'paynl/helper'
9
+ require_relative 'paynl/version'
10
+ require_relative 'paynl/api/validate/is_pay_server_ip'
11
+ require_relative 'paynl/api/validate/get_pay_server_ips'
12
+ require_relative 'paynl/api/transaction/get_service'
13
+ require_relative 'paynl/api/transaction/start_transaction'
14
+ require_relative 'paynl/api/transaction/info'
15
+ require_relative 'paynl/api/transaction/refund'
16
+ require_relative 'paynl/api/api'
17
+ require_relative 'paynl/config'
18
+ require_relative 'paynl/transaction'
19
+ require_relative 'paynl/paymentmethods'
20
+ require_relative 'paynl'
21
21
 
@@ -1,11 +1,11 @@
1
1
  module Paynl
2
2
  module Api
3
3
  class Api
4
- @version = 1;
4
+ @version = 1
5
5
  @@data = Hash.new
6
6
 
7
- @apiTokenRequired = false;
8
- @serviceIdRequired = false;
7
+ @apiTokenRequired = false
8
+ @serviceIdRequired = false
9
9
 
10
10
  def isApiTokenRequired
11
11
  return @apiTokenRequired
@@ -17,13 +17,13 @@ module Paynl
17
17
  end
18
18
 
19
19
  def getData
20
- if self.isApiTokenRequired
20
+ if isApiTokenRequired
21
21
  Paynl::Helper::requireApiToken
22
22
 
23
23
  @@data['token'] = Paynl::Config::getApiToken
24
24
  end
25
25
 
26
- if self.isServiceIdRequired
26
+ if isServiceIdRequired
27
27
  Paynl::Helper::requireServiceId
28
28
 
29
29
  @@data['serviceId'] = Paynl::Config::getServiceId
@@ -42,15 +42,27 @@ module Paynl
42
42
 
43
43
  def doRequest(endpoint, version = nil)
44
44
 
45
- data = self.getData
45
+ data = getData
46
46
  uri = Paynl::Config::getApiUrl(endpoint, version)
47
- # puts uri
48
- # puts data
49
- # Code to actually do the CURL request
50
- response = Typhoeus::Request.post(
51
- uri,
52
- :params => data
53
- )
47
+ #puts uri
48
+ #puts data
49
+
50
+ if isServiceIdRequired
51
+ # Code to actually do the CURL request
52
+ response = Typhoeus::Request.post(
53
+ uri,
54
+ params: data,
55
+ userpwd: Paynl::Config::getTokenCode + ':' + Paynl::Config::getApiToken,
56
+ :headers => { 'User-Agent' => 'Ruby SDK ' + VERSION }
57
+ )
58
+ else
59
+ # Code to actually do the CURL request
60
+ response = Typhoeus::Request.post(
61
+ uri,
62
+ params: data,
63
+ :headers => { 'User-Agent' => 'Ruby SDK ' + VERSION }
64
+ )
65
+ end
54
66
 
55
67
  # if response.code != 200
56
68
  # raise 'API error'
@@ -62,10 +74,10 @@ module Paynl
62
74
  # puts response.headers_hash # http headers put into a hash
63
75
  # puts response.body # the response body
64
76
 
65
- output = self.processResult(JSON.parse(response.body))
77
+ output = processResult(JSON.parse(response.body))
66
78
  return output
67
79
 
68
80
  end
69
81
  end
70
82
  end
71
- end
83
+ end
@@ -14,7 +14,7 @@ module Paynl
14
14
 
15
15
  def doRequest
16
16
  # TODO: add caching to this
17
- return super('transaction/getService', nil)
17
+ return super('transaction/getService', 16)
18
18
  end
19
19
  end
20
20
  end
@@ -38,7 +38,7 @@ module Paynl
38
38
  end
39
39
 
40
40
  def doRequest
41
- return super('transaction/refund', nil)
41
+ return super('transaction/refund', 15)
42
42
  end
43
43
  end
44
44
  end
@@ -157,7 +157,7 @@ module Paynl
157
157
  end
158
158
 
159
159
  unless @paymentOptionId.nil?
160
- @@data['paymentOptionsId'] = @paymentOptionId
160
+ @@data['paymentOptionId'] = @paymentOptionId
161
161
  end
162
162
 
163
163
  if @finishUrl.nil?
@@ -1,10 +1,21 @@
1
1
  module Paynl
2
2
  class Config
3
3
  @@apiToken=''
4
+ @@tokenCode=''
4
5
  @@serviceId=''
5
6
  @@apiBase='https://rest-api.pay.nl'
6
7
  @@apiVersion=5
7
8
 
9
+ # getTokenCode - Retrieves Pay.nl tokencode
10
+ def self.getTokenCode
11
+ return @@tokenCode
12
+ end
13
+
14
+ # setTokenCode - Sets Pay.nl tokencode
15
+ def self.setTokenCode(tokenCode)
16
+ @@tokenCode = tokenCode
17
+ end
18
+
8
19
  # getApiToken - Retrieves Pay.nl api token
9
20
  def self.getApiToken
10
21
  return @@apiToken
@@ -2,11 +2,17 @@ module Paynl
2
2
  class Helper
3
3
  def self.requireApiToken
4
4
  apiToken = Paynl::Config::getApiToken
5
+ tokenCode = Paynl::Config::getTokenCode
5
6
 
6
7
  # Hmm, porting PHP to Ruby is crap if you want to keep the structure
7
8
  if apiToken == nil? or apiToken == ''
8
9
  raise Paynl::Error::Required::ApiTokenError, 'Api token is required'
9
10
  end
11
+
12
+ if tokenCode == nil? or tokenCode == ''
13
+ raise Paynl::Error::Required::ApiTokenError, 'Api token code (AT-code) is required'
14
+ end
15
+
10
16
  end
11
17
 
12
18
  def self.requireServiceId
@@ -29,7 +35,7 @@ module Paynl
29
35
  # Setup basic taxClasses (like in the PHP SDK)
30
36
  taxClasses = Hash.new
31
37
  taxClasses.store(0, 'N')
32
- taxClasses.store(6, 'L')
38
+ taxClasses.store(9, 'L')
33
39
  taxClasses.store(21, 'H')
34
40
 
35
41
  if (taxAmount == 0 || amountInclTax == 0)
@@ -44,10 +50,10 @@ module Paynl
44
50
 
45
51
  def self.transactionIsPaid(transaction)
46
52
  unless transaction.is_a? Hash
47
- raise("Please give me the output of the Paynl::Transaction::getTransaction function")
53
+ raise('Please give me the output of the Paynl::Transaction::getTransaction function')
48
54
  end
49
55
 
50
- if result['paymentDetails']['stateName'] == 'PAID'
56
+ if transaction['paymentDetails']['stateName'] == 'PAID'
51
57
  return true
52
58
  end
53
59
 
@@ -56,10 +62,25 @@ module Paynl
56
62
 
57
63
  def self.transactionIsPending(transaction)
58
64
  unless transaction.is_a? Hash
59
- raise("Please give me the output of the Paynl::Transaction::getTransaction function")
65
+ raise('Please give me the output of the Paynl::Transaction::getTransaction function')
66
+ end
67
+
68
+ if transaction['paymentDetails']['stateName'] == 'PENDING'
69
+ return true
70
+ end
71
+ if transaction['paymentDetails']['stateName'] == 'VERIFY'
72
+ return true
73
+ end
74
+
75
+ return false
76
+ end
77
+
78
+ def self.transactionIsCanceled(transaction)
79
+ unless transaction.is_a? Hash
80
+ raise('Please give me the output of the Paynl::Transaction::getTransaction function')
60
81
  end
61
82
 
62
- if result['paymentDetails']['stateName'] == 'PENDING'
83
+ if transaction['paymentDetails']['stateName'] == 'CANCEL'
63
84
  return true
64
85
  end
65
86
 
@@ -1,3 +1,3 @@
1
1
  module Paynl
2
- VERSION = "0.1.1"
2
+ VERSION = '1.0.4'
3
3
  end
@@ -22,13 +22,12 @@ 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) }
29
28
  spec.require_paths = ["lib"]
30
- spec.add_development_dependency "bundler", "~> 1.11"
31
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "bundler", "~> 2.1"
30
+ spec.add_development_dependency "rake", "~> 13.0"
32
31
  spec.add_development_dependency "rspec", "~> 3.0"
33
32
  # spec.add_development_dependency "spec"
34
33
  # spec.add_development_dependency "spectask"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paynl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Berm
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-28 00:00:00.000000000 Z
11
+ date: 2020-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.11'
19
+ version: '2.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.11'
26
+ version: '2.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -75,6 +75,7 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".gitignore"
78
+ - ".gitlab-ci.yml"
78
79
  - ".rspec"
79
80
  - ".travis.yml"
80
81
  - Gemfile
@@ -119,8 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
120
  - !ruby/object:Gem::Version
120
121
  version: '0'
121
122
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.4.6
123
+ rubygems_version: 3.1.2
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Simple interface to create transactions for the Pay.nl PSP