trustly-client-ruby 0.1.8 → 0.1.71

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20e58d7cb248d8adfa149f89eaba36b8bfe9c520
4
- data.tar.gz: 71ef2a4aeef7e028b8054387fa72055cb7fdff0a
3
+ metadata.gz: 5421b7c57a5df06f7871d9293ade9e0a55b29aee
4
+ data.tar.gz: 1e54994705a9e3e79ea9a06c6c43cfe2f34909e4
5
5
  SHA512:
6
- metadata.gz: 547c1f23f5a1564f0c575bf7a3cbf0a76df3a46e850b0c3d3e290122ebdda9774b1328a03c91b9494dce20c6772b340a694420305e0c2ea6a749f5446633b82d
7
- data.tar.gz: 5784007b972a3af3ef8febe82b93490985067490a3ee3f945654ae711c562f437b3da398653132cbe265f3f8a1c79185a869a18fc483566df00e07e0d343d07a
6
+ metadata.gz: 47efca17a1ba7c273263975eed75c282d931af84f3bafad39943228fb8f781aaf449a4ca23c1e4a94295111f89db4968ce90c87d42d674876007480b93d0456a
7
+ data.tar.gz: 9fc39003d366ac87d52c956eb71627260c58d0f4274137062575b411fe258220e1595d4b84cd3506ed93a6871e661c0e8a53c5ebcf2337950d76199e5b9f39f6
data/README.md CHANGED
@@ -1,176 +1,38 @@
1
- # Trustly-client-ruby
1
+ # Trustly::Client::Ruby
2
2
 
3
- This is an example implementation of communication with the Trustly API using Ruby. This a ruby gem that allows you use Trustly Api calls in ruby. It's based on [trustly-client-python] (https://github.com/trustly/trustly-client-python) and [turstly-client-php] (https://github.com/trustly/trustly-client-php)
4
-
5
- It implements the standard Payments API as well as gives stubs for executing calls against the API used by the backoffice.
6
-
7
- For full documentation on the Trustly API internals visit our developer website: http://trustly.com/developer . All information about software flows and call patters can be found on that site. The documentation within this code will only cover the code itself, not how you use the Trustly API.
8
-
9
- This code is provided as-is, use it as inspiration, reference or drop it directly into your own project and use it.
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/trustly/client/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
10
4
 
5
+ TODO: Delete this and the text above, and describe your gem
11
6
 
12
7
  ## Installation
13
8
 
14
9
  Add this line to your application's Gemfile:
15
10
 
16
11
  ```ruby
17
- gem 'trustly-client-ruby',:require=>'trustly'
12
+ gem 'trustly-client-ruby'
18
13
  ```
19
14
 
20
15
  And then execute:
21
16
 
22
- $ bundle install
17
+ $ bundle
23
18
 
24
19
  Or install it yourself as:
25
20
 
26
21
  $ gem install trustly-client-ruby
27
22
 
28
- If you use rails, you can use this generator in order to let trustly find your certificates:
29
-
30
- $ rails g trustly:install
31
-
32
- This will copy trustly public certificates under certs/trustly folder:
33
-
34
- certs/trustly/test.trustly.public.pem
35
- certs/trustly/live.trustly.public.pem
36
-
37
- You will need to copy test and live private certificates using this naming convention (if you want Trustly to load them automatically but you can use different path and names):
38
-
39
- certs/trustly/test.merchant.private.pem
40
- certs/trustly/live.merchant.private.pem
41
-
42
23
  ## Usage
43
24
 
44
- Currently only **Deposit** and **Refund** api calls. However, other calls can be implemented very easily.
45
-
46
- ### Api
47
-
48
- In order to use Trustly Api, we'll need to create a **Trustly::Api::Signed**. Example:
49
-
50
- ```ruby
51
- api = Trustly::Api::Signed.new({
52
- :username=>"yourusername",
53
- :password=>"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
54
- })
55
- ```
56
-
57
- This will automatically load pem files from **certs/trustly** with default optons. If you want to specify other paths or options then you can call:
58
-
59
- ```ruby
60
- api = Trustly::Api::Signed.new({
61
- :username=>"yourusername",
62
- :password=>"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
63
- :host => 'test.trustly.com',
64
- :port => 443,
65
- :is_https => true,
66
- :private_pem => "#{Rails.root}/certs/trustly/test.merchant.private.pem",
67
- :public_pem => "#{Rails.root}/certs/trustly/test.trustly.public.pem"
68
- })
69
- ```
70
-
71
- ### Deposit call
72
-
73
- Deposit is straightfoward call. Only required arguments example:
74
-
75
- ```ruby
76
- deposit = api.deposit({"EndUserID"=>10002,"MessageID"=>12349,"Amount"=>3})
77
- ```
78
- Optional arguments are:
79
-
80
- - Locale: default value "es_ES"
81
- - Country: default "ES"
82
- - Currency default "EUR"
83
- - SuggestedMinAmount
84
- - SuggestedMaxAmount
85
- - Amount
86
- - Currency
87
- - Country
88
- - IP
89
- - SuccessURL: default "https://www.trustly.com/success"
90
- - FailURL : default "https://www.trustly.com/fail"
91
- - TemplateURL
92
- - URLTarget
93
- - MobilePhone
94
- - Firstname
95
- - Lastname
96
- - NationalIdentificationNumber
97
- - ShopperStatement
98
- - NotificationURL: default "https://test.trustly.com/demo/notifyd_test"
99
-
100
- This will return a **Trustly::Data::JSONRPCResponse**:
101
-
102
- ```ruby
103
- > deposit.get_data('url')
104
- => "https://test.trustly.com/_/orderclient.php?SessionID=755ea475-dcf1-476e-ac70-07913501b34e&OrderID=4257552724&Locale=es_ES"
105
-
106
- > deposit.get_data()
107
- => {
108
- "orderid" => "4257552724",
109
- "url" => "https://test.trustly.com/_/orderclient.php?SessionID=755ea475-dcf1-476e-ac70-07913501b34e&OrderID=4257552724&Locale=es_ES"
110
- }
111
- ```
112
-
113
- You can check if there was an error:
114
-
115
- ```ruby
116
- > deposit.error?
117
- => true
118
-
119
- > deposit.success?
120
- => false
121
-
122
- > deposit.error_msg
123
- => "ERROR_DUPLICATE_MESSAGE_ID"
124
- ```
125
-
126
- ### Refund call
127
-
25
+ TODO: Write usage instructions here
128
26
 
27
+ ## Development
129
28
 
130
- ### Notifications
131
-
132
- After a **deposit** or **refund** call, Trustly will send a notification to **NotificationURL**. If you are using rails the execution flow will look like this:
133
-
134
- ```ruby
135
- def controller_action
136
- api = Trustly::Api::Signed.new({..})
137
- notification = Trustly::JSONRPCNotificationRequest.new(params)
138
- if api.verify_trustly_signed_notification(notification)
139
- # do something with notification
140
- ...
141
- # reply to trustly
142
- response = api.notification_response(notification,true)
143
- render :text => response.json()
144
- else
145
- render :nothing => true, :status => 200
146
- end
147
- end
148
- ```
149
-
150
- You can use **Trustly::JSONRPCNotificationRequest** object to access data provided using the following methods:
151
-
152
- ```ruby
153
- notification.get_data
154
- => {"amount"=>"902.50", "currency"=>"EUR", "messageid"=>"98348932", "orderid"=>"87654567", "enduserid"=>"32123", "notificationid"=>"9876543456", "timestamp"=>"2010-01-20 14:42:04.675645+01", "attributes"=>{}}
155
-
156
- > notification.get_method
157
- => "credit"
158
-
159
- > notification.get_uuid
160
- => "258a2184-2842-b485-25ca-293525152425"
161
-
162
- > notification.get_signature
163
- => "R9+hjuMqbsH0Ku ... S16VbzRsw=="
164
-
165
- > notification.get_data('amount')
166
- => "902.50"
167
- ```
168
-
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
169
30
 
31
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
170
32
 
171
33
  ## Contributing
172
34
 
173
- 1. Fork it ( https://github.com/jcarreti/trustly-client-ruby/fork )
35
+ 1. Fork it ( https://github.com/[my-github-username]/trustly-client-ruby/fork )
174
36
  2. Create your feature branch (`git checkout -b my-new-feature`)
175
37
  3. Commit your changes (`git commit -am 'Add some feature'`)
176
38
  4. Push to the branch (`git push origin my-new-feature`)
@@ -13,8 +13,8 @@ require "trustly/data/request"
13
13
  require "trustly/data/response"
14
14
  require "trustly/data/jsonrpc_request"
15
15
  require "trustly/data/jsonrpc_response"
16
- require "trustly/data/jsonrpcnotification_request"
17
- require "trustly/data/jsonrpcnotification_response"
16
+ require "trustly/data/jsonrpcnotificationrequest"
17
+ require "trustly/data/jsonrpcnotificationrequest"
18
18
 
19
19
  require "trustly/api"
20
20
  require "trustly/api/signed"
@@ -0,0 +1,19 @@
1
+ module Trustly
2
+ end
3
+
4
+ require "trustly/exception/authentification_error"
5
+ require "trustly/exception/connection_error"
6
+ require "trustly/exception/data_error"
7
+ require "trustly/exception/jsonrpc_version_error"
8
+ require "trustly/exception/signature_error"
9
+
10
+ require "trustly/data"
11
+ require "trustly/data/jsonrpc_request"
12
+ require "trustly/data/jsonrpc_response"
13
+ require "trustly/data/jsonrpcnotificationrequest"
14
+ require "trustly/data/jsonrpcnotificationrequest"
15
+
16
+ require "trustly/api"
17
+ require "trustly/api/signed"
18
+ require "trustly/version"
19
+
@@ -46,14 +46,6 @@ class Trustly::Api
46
46
  raise NotImplementedError
47
47
  end
48
48
 
49
- def verify_trustly_signed_notification(response)
50
- method = response.get_method()
51
- uuid = response.get_uuid()
52
- signature = response.get_signature()
53
- data = response.get_data()
54
- return self._verify_trustly_signed_data(method, uuid, signature, data)
55
- end
56
-
57
49
  protected
58
50
 
59
51
  def _verify_trustly_signed_data(method, uuid, signature, data)
@@ -72,6 +64,13 @@ class Trustly::Api
72
64
  return self._verify_trustly_signed_data(method, uuid, signature, data)
73
65
  end
74
66
 
67
+ def verify_trustly_signed_notification(response)
68
+ method = response.get_method()
69
+ uuid = response.get_uuid()
70
+ signature = response.get_signature()
71
+ data = response.get_data()
72
+ return self._verify_trustly_signed_data(method, uuid, signature, data)
73
+ end
75
74
 
76
75
  def set_host(host=nil,port=nil,is_https=nil)
77
76
  self.api_host = host unless host.nil?
@@ -110,24 +110,6 @@ class Trustly::Api::Signed < Trustly::Api
110
110
  #options["HoldNotifications"] = "1" unless
111
111
  end
112
112
 
113
- def refund(_options)
114
- options = {
115
- "OrderID" => "EUR"
116
- }.merge(_options)
117
-
118
- # check for required options
119
- ["OrderID","Amount","Currency"].each{|req_attr| raise Trustly::Exception::DataError, "Option not valid '#{req_attr}'" if options.try(:[],req_attr).nil? }
120
-
121
- request = Trustly::Data::JSONRPCRequest.new('Deposit',options,nil)
122
- return self.call_rpc(request)
123
- end
124
-
125
- def notification_response(notification,success=true)
126
- response = Trustly::JSONRPCNotificationResponse.new(notification,success)
127
- response.set_signature(self.sign_merchant_request(notification))
128
- return notification
129
- end
130
-
131
113
  def withdraw(_options)
132
114
 
133
115
  end
@@ -3,19 +3,15 @@ class Trustly::JSONRPCNotificationRequest < Trustly::Data
3
3
  attr_accessor :notification_body, :payload
4
4
 
5
5
  def initialize(notification_body)
6
- super()
6
+ super
7
7
  self.notification_body = notification_body
8
- unless self.notification_body.is_a?(Hash)
9
- begin
10
- self.payload = JSON.parse(self.notification_body)
11
- rescue JSON::ParserError => e
12
- raise Trustly::Exception::DataError, e.message
13
- end
14
-
15
- raise Trustly::Exception::JSONRPCVersionError, 'JSON RPC Version #{(self.get_version()} is not supported' if self.get_version() != '1.1'
16
- else
17
- self.payload = self.notification_body.deep_stringify_keys
8
+ begin
9
+ self.payload = JSON.parse(self.notification_body)
10
+ rescue JSON::ParserError => e
11
+ raise Trustly::Exception::DataError, e.message
18
12
  end
13
+
14
+ raise Trustly::Exception::JSONRPCVersionError, 'JSON RPC Version #{(self.get_version()} is not supported' if self.get_version() != '1.1'
19
15
  end
20
16
 
21
17
  def get_version()
@@ -1,3 +1,3 @@
1
1
  module Trustly
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.71"
3
3
  end
@@ -0,0 +1,3 @@
1
+ module Trustly
2
+ VERSION = "0.1.7"
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trustly-client-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jorge Carretie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-02 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -50,13 +50,14 @@ files:
50
50
  - lib/generators/trustly/templates/live.trustly.public.pem
51
51
  - lib/generators/trustly/templates/test.trustly.public.pem
52
52
  - lib/trustly.rb
53
+ - lib/trustly.rb~
53
54
  - lib/trustly/api.rb
54
55
  - lib/trustly/api/signed.rb
55
56
  - lib/trustly/data.rb
56
57
  - lib/trustly/data/jsonrpc_request.rb
57
58
  - lib/trustly/data/jsonrpc_response.rb
58
- - lib/trustly/data/jsonrpcnotification_request.rb
59
- - lib/trustly/data/jsonrpcnotification_response.rb
59
+ - lib/trustly/data/jsonrpcnotificationrequest.rb
60
+ - lib/trustly/data/jsonrpcnotificationresponse.rb
60
61
  - lib/trustly/data/request.rb
61
62
  - lib/trustly/data/response.rb
62
63
  - lib/trustly/exception.rb
@@ -66,6 +67,7 @@ files:
66
67
  - lib/trustly/exception/jsonrpc_version_error.rb
67
68
  - lib/trustly/exception/signature_error.rb
68
69
  - lib/trustly/version.rb
70
+ - lib/trustly/version.rb~
69
71
  homepage: https://github.com/jcarreti/trusty-client-ruby
70
72
  licenses:
71
73
  - MIT