trustly-client-ruby 0.1.71 → 0.1.72

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: 5421b7c57a5df06f7871d9293ade9e0a55b29aee
4
- data.tar.gz: 1e54994705a9e3e79ea9a06c6c43cfe2f34909e4
3
+ metadata.gz: bc918b9581ec07800276b9891f056e70ddd0255d
4
+ data.tar.gz: 0523cdbef296a53d138dee5cfb16d701c5700f5f
5
5
  SHA512:
6
- metadata.gz: 47efca17a1ba7c273263975eed75c282d931af84f3bafad39943228fb8f781aaf449a4ca23c1e4a94295111f89db4968ce90c87d42d674876007480b93d0456a
7
- data.tar.gz: 9fc39003d366ac87d52c956eb71627260c58d0f4274137062575b411fe258220e1595d4b84cd3506ed93a6871e661c0e8a53c5ebcf2337950d76199e5b9f39f6
6
+ metadata.gz: 4b7655ca5fd49dd69b17f8763b6051f76db51ee946b37666de9bfbe53452988645b8d9b3f2c9a53728740efc6bf36b5f8a916ef96e33f26afeffb803de1480f2
7
+ data.tar.gz: 84e93a63069ed1cceebcf2738dd36aad4d78db650cc423221048795d984e5503704d58f8583f0054d4b2f1d282e9dbb1d13a93f0155796bd769e4701aac697cf
data/README.md CHANGED
@@ -1,38 +1,176 @@
1
- # Trustly::Client::Ruby
1
+ # Trustly-client-ruby
2
2
 
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.
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.
4
10
 
5
- TODO: Delete this and the text above, and describe your gem
6
11
 
7
12
  ## Installation
8
13
 
9
14
  Add this line to your application's Gemfile:
10
15
 
11
16
  ```ruby
12
- gem 'trustly-client-ruby'
17
+ gem 'trustly-client-ruby',:require=>'trustly'
13
18
  ```
14
19
 
15
20
  And then execute:
16
21
 
17
- $ bundle
22
+ $ bundle install
18
23
 
19
24
  Or install it yourself as:
20
25
 
21
26
  $ gem install trustly-client-ruby
22
27
 
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
+
23
42
  ## Usage
24
43
 
25
- TODO: Write usage instructions here
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
+
26
128
 
27
- ## Development
28
129
 
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.
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
+
30
169
 
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).
32
170
 
33
171
  ## Contributing
34
172
 
35
- 1. Fork it ( https://github.com/[my-github-username]/trustly-client-ruby/fork )
173
+ 1. Fork it ( https://github.com/jcarreti/trustly-client-ruby/fork )
36
174
  2. Create your feature branch (`git checkout -b my-new-feature`)
37
175
  3. Commit your changes (`git commit -am 'Add some feature'`)
38
176
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/trustly.rb CHANGED
@@ -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/jsonrpcnotificationrequest"
17
- require "trustly/data/jsonrpcnotificationrequest"
16
+ require "trustly/data/jsonrpcnotification_request"
17
+ require "trustly/data/jsonrpcnotification_request"
18
18
 
19
19
  require "trustly/api"
20
20
  require "trustly/api/signed"
@@ -110,6 +110,24 @@ 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
+
113
131
  def withdraw(_options)
114
132
 
115
133
  end
@@ -3,15 +3,19 @@ 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
- begin
9
- self.payload = JSON.parse(self.notification_body)
10
- rescue JSON::ParserError => e
11
- raise Trustly::Exception::DataError, e.message
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
12
18
  end
13
-
14
- raise Trustly::Exception::JSONRPCVersionError, 'JSON RPC Version #{(self.get_version()} is not supported' if self.get_version() != '1.1'
15
19
  end
16
20
 
17
21
  def get_version()
@@ -1,3 +1,3 @@
1
1
  module Trustly
2
- VERSION = "0.1.71"
2
+ VERSION = "0.1.72"
3
3
  end
@@ -1,3 +1,3 @@
1
1
  module Trustly
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.71"
3
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.71
4
+ version: 0.1.72
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-06-30 00:00:00.000000000 Z
11
+ date: 2015-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -50,14 +50,13 @@ 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~
54
53
  - lib/trustly/api.rb
55
54
  - lib/trustly/api/signed.rb
56
55
  - lib/trustly/data.rb
57
56
  - lib/trustly/data/jsonrpc_request.rb
58
57
  - lib/trustly/data/jsonrpc_response.rb
59
- - lib/trustly/data/jsonrpcnotificationrequest.rb
60
- - lib/trustly/data/jsonrpcnotificationresponse.rb
58
+ - lib/trustly/data/jsonrpcnotification_request.rb
59
+ - lib/trustly/data/jsonrpcnotification_response.rb
61
60
  - lib/trustly/data/request.rb
62
61
  - lib/trustly/data/response.rb
63
62
  - lib/trustly/exception.rb
data/lib/trustly.rb~ DELETED
@@ -1,19 +0,0 @@
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
-