paytrail 0.0.0 → 0.0.2
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/lib/paytrail.rb +13 -7
- data/lib/paytrail/merchantapi.rb +5 -5
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e52de41101a3fcea1ccd68d46a9fb08b308d6ff8
|
|
4
|
+
data.tar.gz: 12d147acb31fa42031046812cedc10492edf2722
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a9df305a15c3431738636052e65aade7670238312055aff2262d1b67c03bb74adf882c52df88c6b71f30884f52d0be76d3998b86a8a759b1d6e0eeb27309ef44
|
|
7
|
+
data.tar.gz: a22ca2ac9fdc3d9253d745cf7205fa533e197f4aa6fb22e7bd0288e15f0a52c9b5951a6a317e7ea4363a54e27ad57a573b4f11349fd5facf75759ab467b7692e
|
data/lib/paytrail.rb
CHANGED
|
@@ -7,27 +7,33 @@ require 'net/http'
|
|
|
7
7
|
require 'uri'
|
|
8
8
|
|
|
9
9
|
class Paytrail
|
|
10
|
+
def initialize(apiName, apiKey, secret)
|
|
11
|
+
@apiName = apiName
|
|
12
|
+
@apiKey = apiKey
|
|
13
|
+
@secret = secret
|
|
14
|
+
end
|
|
15
|
+
|
|
10
16
|
def makeTimestamp()
|
|
11
17
|
Time.now.iso8601
|
|
12
18
|
end
|
|
13
19
|
|
|
14
|
-
def makeAuthorization(
|
|
15
|
-
signatureData = "%s\n%s\n%s %s\n%s\n%s" % [method,
|
|
20
|
+
def makeAuthorization(method, location, timestamp, contentMD5)
|
|
21
|
+
signatureData = "%s\n%s\n%s %s\n%s\n%s" % [method, location, @apiName, @apiKey, timestamp, contentMD5]
|
|
16
22
|
digest = OpenSSL::Digest::SHA256.new
|
|
17
|
-
hmac = OpenSSL::HMAC.digest(digest, secret, signatureData)
|
|
23
|
+
hmac = OpenSSL::HMAC.digest(digest, @secret, signatureData)
|
|
18
24
|
|
|
19
|
-
Base64.
|
|
25
|
+
Base64.strict_encode64(hmac)
|
|
20
26
|
end
|
|
21
27
|
|
|
22
28
|
def makeContentMD5(content)
|
|
23
29
|
Digest::MD5.base64digest content
|
|
24
30
|
end
|
|
25
31
|
|
|
26
|
-
def makeHeaders(
|
|
32
|
+
def makeHeaders(method, location, timestamp, body)
|
|
27
33
|
{
|
|
28
34
|
'Timestamp' => timestamp,
|
|
29
35
|
'Content-MD5' => makeContentMD5(body),
|
|
30
|
-
'Authorization' => "%s %s:%s" % [apiName, apiKey, makeAuthorization(
|
|
36
|
+
'Authorization' => "%s %s:%s" % [@apiName, @apiKey, makeAuthorization(method, location, timestamp, makeContentMD5(body))]
|
|
31
37
|
}
|
|
32
38
|
end
|
|
33
39
|
|
|
@@ -47,7 +53,7 @@ class Paytrail
|
|
|
47
53
|
end
|
|
48
54
|
|
|
49
55
|
def makeRequest(uri, request)
|
|
50
|
-
http = Net::HTTP.start(uri.hostname, uri.port
|
|
56
|
+
http = Net::HTTP.start(uri.hostname, uri.port)
|
|
51
57
|
|
|
52
58
|
http.request(request)
|
|
53
59
|
end
|
data/lib/paytrail/merchantapi.rb
CHANGED
|
@@ -3,6 +3,8 @@ require 'paytrail'
|
|
|
3
3
|
class Paytrail::MerchantApi
|
|
4
4
|
# Example usage
|
|
5
5
|
#
|
|
6
|
+
# require 'paytrail/merchantapi'
|
|
7
|
+
#
|
|
6
8
|
# merchantApi = Paytrail::MerchantApi.new(13466, '6pKF4jkv97zmqBJ3ZL8gUw5DfT2NMQ', 'https://api.paytrail.com')
|
|
7
9
|
# response = merchantApi.createRefund(
|
|
8
10
|
# 'ORD-59867',
|
|
@@ -44,10 +46,8 @@ class Paytrail::MerchantApi
|
|
|
44
46
|
@@apiName = 'PaytrailMerchantAPI'
|
|
45
47
|
|
|
46
48
|
def initialize(apiKey, secret, uri)
|
|
47
|
-
@
|
|
48
|
-
@secret = secret
|
|
49
|
+
@paytrail = Paytrail.new(@@apiName, apiKey, secret)
|
|
49
50
|
@uri = uri
|
|
50
|
-
@paytrail = Paytrail.new
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
def createRefund(orderNumber, email, refundRows, notifyUrl)
|
|
@@ -62,14 +62,14 @@ class Paytrail::MerchantApi
|
|
|
62
62
|
|
|
63
63
|
data = data.to_json
|
|
64
64
|
location = '/merchant/v1/payments/%s/refunds' % [orderNumber]
|
|
65
|
-
headers = @paytrail.makeHeaders(
|
|
65
|
+
headers = @paytrail.makeHeaders('POST', location, @paytrail.makeTimestamp, data)
|
|
66
66
|
|
|
67
67
|
@paytrail.post(@uri + location, headers, data)
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def deleteRefund(refundToken)
|
|
71
71
|
location = '/merchant/v1/refunds/%s' % [refundToken]
|
|
72
|
-
headers = @paytrail.makeHeaders(
|
|
72
|
+
headers = @paytrail.makeHeaders('DELETE', location, @paytrail.makeTimestamp, '')
|
|
73
73
|
|
|
74
74
|
@paytrail.delete(@uri + location, headers)
|
|
75
75
|
end
|
metadata
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: paytrail
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
|
-
- Johanna
|
|
7
|
+
- Johanna Pelkonen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-
|
|
11
|
+
date: 2015-12-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Paytrail Merchant API allows merchant to create and delete refunds for
|
|
14
14
|
payments made via Paytrail
|
|
15
|
-
email: johanna.
|
|
15
|
+
email: johanna.pelkonen@paytrail.com
|
|
16
16
|
executables: []
|
|
17
17
|
extensions: []
|
|
18
18
|
extra_rdoc_files: []
|