kaznachey_payments 0.9.7.7

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.
Files changed (51) hide show
  1. checksums.yaml +15 -0
  2. data/Gemfile +9 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +50 -0
  5. data/Rakefile +2 -0
  6. data/doc/HttpHelper.html +221 -0
  7. data/doc/KaznacheyConfigurations.html +132 -0
  8. data/doc/KaznacheyPayments.html +117 -0
  9. data/doc/KaznacheyPaymentsApi.html +294 -0
  10. data/doc/Md5Helper.html +189 -0
  11. data/doc/PaySystem.html +430 -0
  12. data/doc/PaymentDetails.html +900 -0
  13. data/doc/Product.html +480 -0
  14. data/doc/ReqCommonObject.html +274 -0
  15. data/doc/ReqCreatePayment.html +534 -0
  16. data/doc/ReqGetMerchantInfo.html +202 -0
  17. data/doc/RespCommonObject.html +274 -0
  18. data/doc/RespCreatePayment.html +303 -0
  19. data/doc/RespMerchantInfo.html +387 -0
  20. data/doc/RespPaymentStatus.html +689 -0
  21. data/doc/_index.html +212 -0
  22. data/doc/class_list.html +58 -0
  23. data/doc/css/common.css +1 -0
  24. data/doc/css/full_list.css +57 -0
  25. data/doc/css/style.css +339 -0
  26. data/doc/file.README.html +110 -0
  27. data/doc/file_list.html +60 -0
  28. data/doc/frames.html +26 -0
  29. data/doc/index.html +126 -0
  30. data/doc/js/app.js +219 -0
  31. data/doc/js/full_list.js +181 -0
  32. data/doc/js/jquery.js +4 -0
  33. data/doc/method_list.html +333 -0
  34. data/doc/top-level-namespace.html +114 -0
  35. data/lib/ApiObjects/Requests/payment_details.rb +34 -0
  36. data/lib/ApiObjects/Requests/product.rb +16 -0
  37. data/lib/ApiObjects/Requests/req_common_object.rb +6 -0
  38. data/lib/ApiObjects/Requests/req_create_payment.rb +42 -0
  39. data/lib/ApiObjects/Requests/req_get_merchant_info.rb +11 -0
  40. data/lib/ApiObjects/Responses/pay_system.rb +19 -0
  41. data/lib/ApiObjects/Responses/resp_common_object.rb +6 -0
  42. data/lib/ApiObjects/Responses/resp_create_payment.rb +15 -0
  43. data/lib/ApiObjects/Responses/resp_merchant_info.rb +26 -0
  44. data/lib/ApiObjects/Responses/resp_payment_status.rb +43 -0
  45. data/lib/ApiObjects/kaznachey_configurations.rb +9 -0
  46. data/lib/Helpers/http_helper.rb +26 -0
  47. data/lib/Helpers/md5_helper.rb +7 -0
  48. data/lib/kaznachey_payments/version.rb +3 -0
  49. data/lib/kaznachey_payments_api.rb +32 -0
  50. data/test/test_get_merchant_info.rb +55 -0
  51. metadata +95 -0
@@ -0,0 +1,114 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.8.7.6
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
16
+
17
+ <script type="text/javascript" charset="utf-8">
18
+ hasFrames = window.top.frames.main ? true : false;
19
+ relpath = '';
20
+ framesUrl = "frames.html#!top-level-namespace.html";
21
+ </script>
22
+
23
+
24
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
25
+
26
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
27
+
28
+
29
+ </head>
30
+ <body>
31
+ <div id="header">
32
+ <div id="menu">
33
+
34
+ <a href="_index.html">Index</a> &raquo;
35
+
36
+
37
+ <span class="title">Top Level Namespace</span>
38
+
39
+
40
+ <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
41
+ </div>
42
+
43
+ <div id="search">
44
+
45
+ <a class="full_list_link" id="class_list_link"
46
+ href="class_list.html">
47
+ Class List
48
+ </a>
49
+
50
+ <a class="full_list_link" id="method_list_link"
51
+ href="method_list.html">
52
+ Method List
53
+ </a>
54
+
55
+ <a class="full_list_link" id="file_list_link"
56
+ href="file_list.html">
57
+ File List
58
+ </a>
59
+
60
+ </div>
61
+ <div class="clear"></div>
62
+ </div>
63
+
64
+ <iframe id="search_frame"></iframe>
65
+
66
+ <div id="content"><h1>Top Level Namespace
67
+
68
+
69
+
70
+ </h1>
71
+
72
+ <dl class="box">
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+ </dl>
82
+ <div class="clear"></div>
83
+
84
+ <h2>Defined Under Namespace</h2>
85
+ <p class="children">
86
+
87
+
88
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="KaznacheyPayments.html" title="KaznacheyPayments (module)">KaznacheyPayments</a></span>
89
+
90
+
91
+
92
+ <strong class="classes">Classes:</strong> <span class='object_link'><a href="HttpHelper.html" title="HttpHelper (class)">HttpHelper</a></span>, <span class='object_link'><a href="KaznacheyConfigurations.html" title="KaznacheyConfigurations (class)">KaznacheyConfigurations</a></span>, <span class='object_link'><a href="KaznacheyPaymentsApi.html" title="KaznacheyPaymentsApi (class)">KaznacheyPaymentsApi</a></span>, <span class='object_link'><a href="Md5Helper.html" title="Md5Helper (class)">Md5Helper</a></span>, <span class='object_link'><a href="PaySystem.html" title="PaySystem (class)">PaySystem</a></span>, <span class='object_link'><a href="PaymentDetails.html" title="PaymentDetails (class)">PaymentDetails</a></span>, <span class='object_link'><a href="Product.html" title="Product (class)">Product</a></span>, <span class='object_link'><a href="ReqCommonObject.html" title="ReqCommonObject (class)">ReqCommonObject</a></span>, <span class='object_link'><a href="ReqCreatePayment.html" title="ReqCreatePayment (class)">ReqCreatePayment</a></span>, <span class='object_link'><a href="ReqGetMerchantInfo.html" title="ReqGetMerchantInfo (class)">ReqGetMerchantInfo</a></span>, <span class='object_link'><a href="RespCommonObject.html" title="RespCommonObject (class)">RespCommonObject</a></span>, <span class='object_link'><a href="RespCreatePayment.html" title="RespCreatePayment (class)">RespCreatePayment</a></span>, <span class='object_link'><a href="RespMerchantInfo.html" title="RespMerchantInfo (class)">RespMerchantInfo</a></span>, <span class='object_link'><a href="RespPaymentStatus.html" title="RespPaymentStatus (class)">RespPaymentStatus</a></span>
93
+
94
+
95
+ </p>
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+ </div>
106
+
107
+ <div id="footer">
108
+ Generated on Wed Dec 3 14:19:56 2014 by
109
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
110
+ 0.8.7.6 (ruby-1.9.3).
111
+ </div>
112
+
113
+ </body>
114
+ </html>
@@ -0,0 +1,34 @@
1
+ class PaymentDetails
2
+ #Order id in merchant's system
3
+ attr_accessor :MerchantInternalPaymentId
4
+
5
+ #User id in merchant's system
6
+ attr_accessor :MerchantInternalUserId
7
+
8
+ #Buyer email
9
+ attr_accessor :EMail
10
+
11
+ #Buyer phone
12
+ attr_accessor :PhoneNumber
13
+
14
+ #Custom info like comments, etc
15
+ attr_accessor :CustomMerchantInfo
16
+
17
+ #Url which receive payment status after paying
18
+ attr_accessor :StatusUrl
19
+
20
+ #Url to redirect buyer after paying
21
+ attr_accessor :ReturnUrl
22
+
23
+ #Buyer first name
24
+ attr_accessor :BuyerFirstname
25
+
26
+ #Buyer last name
27
+ attr_accessor :BuyerLastname
28
+
29
+ #Delivery type
30
+ attr_accessor :DeliveryType
31
+
32
+ #Delivery address
33
+ attr_accessor :BuyerStreet
34
+ end
@@ -0,0 +1,16 @@
1
+ class Product
2
+ #Quantity
3
+ attr_accessor :ProductItemsNum
4
+
5
+ #Name
6
+ attr_accessor :ProductName
7
+
8
+ #Price
9
+ attr_accessor :ProductPrice
10
+
11
+ #Id or code in merchant's system
12
+ attr_accessor :ProductId
13
+
14
+ #Image url
15
+ attr_accessor :ProductImageUrl
16
+ end
@@ -0,0 +1,6 @@
1
+ class ReqCommonObject
2
+ # Generated in each request by GenerateSign method
3
+ attr_accessor :Signature
4
+
5
+ attr_accessor :MerchantGuid
6
+ end
@@ -0,0 +1,42 @@
1
+ require_relative 'req_common_object'
2
+ require 'ApiObjects/kaznachey_configurations'
3
+ require 'Helpers/md5_helper'
4
+
5
+ class ReqCreatePayment < ReqCommonObject
6
+
7
+ # Chosen by buyer payment system
8
+ attr_accessor :SelectedPaySystemId
9
+
10
+ # Buyer info
11
+ attr_accessor :PaymentDetails
12
+
13
+ # Products in order
14
+ attr_accessor :Products
15
+
16
+ attr_accessor :MerchantGuid
17
+
18
+ def GenerateSign
19
+ sum = 0
20
+ count = 0
21
+ if @Products != nil
22
+ @Products.each do |product|
23
+ sum += product.ProductPrice * product.ProductItemsNum
24
+ count += product.ProductItemsNum
25
+
26
+ product.ProductPrice = format('%.2f', product.ProductPrice)
27
+ product.ProductItemsNum = format('%.2f', product.ProductItemsNum)
28
+ end
29
+ end
30
+
31
+ str = @MerchantGuid.upcase
32
+ str += format('%.2f', sum)
33
+ str += format('%.2f', count)
34
+ str += @PaymentDetails.MerchantInternalUserId ||= '0'
35
+ str += @PaymentDetails.MerchantInternalPaymentId ||= '0'
36
+ str += @SelectedPaySystemId.to_s
37
+ str += KaznacheyConfigurations.MerchantSecretKey.upcase
38
+ @Signature = Md5Helper.GetMd5FromString(
39
+ str
40
+ );
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ require_relative 'req_common_object'
2
+ require 'ApiObjects/kaznachey_configurations'
3
+ require 'Helpers/md5_helper'
4
+
5
+ class ReqGetMerchantInfo < ReqCommonObject
6
+
7
+ def GenerateSign
8
+ @Signature = Md5Helper.GetMd5FromString(KaznacheyConfigurations.MerchantGuid.upcase + KaznacheyConfigurations.MerchantSecretKey.upcase);
9
+ end
10
+
11
+ end
@@ -0,0 +1,19 @@
1
+ class PaySystem
2
+
3
+ def initialize(jsonParams)
4
+ if(jsonParams != nil)
5
+ @Id = jsonParams['Id']
6
+ @PaySystemName = jsonParams['PaySystemName']
7
+ @PaySystemTag = jsonParams['PaySystemTag']
8
+ end
9
+ end
10
+
11
+ # Unique payment system id
12
+ attr_accessor :Id
13
+
14
+ # Payment system title
15
+ attr_accessor :PaySystemName
16
+
17
+ # Payment system short name
18
+ attr_accessor :PaySystemTag
19
+ end
@@ -0,0 +1,6 @@
1
+ class RespCommonObject
2
+ attr_accessor :DebugMessage
3
+
4
+ # Success = 0
5
+ attr_accessor :ErrorCode
6
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'resp_common_object'
2
+
3
+ class RespCreatePayment < RespCommonObject
4
+
5
+ # Html code in base64 that need to append into the page
6
+ attr_accessor :ExternalForm
7
+
8
+ def initialize(jsonParams)
9
+ if jsonParams != nil
10
+ @DebugMessage = jsonParams['DebugMessage']
11
+ @ErrorCode = jsonParams['ErrorCode']
12
+ @ExternalForm = jsonParams['ExternalForm']
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'resp_common_object'
2
+ require_relative 'pay_system'
3
+
4
+
5
+ class RespMerchantInfo < RespCommonObject
6
+ def initialize(jsonParams)
7
+ if(jsonParams != nil)
8
+ @ErrorCode = jsonParams['ErrorCode']
9
+ @DebugMessage = jsonParams['DebugMessage']
10
+ @TermToUse = jsonParams['TermToUse']
11
+
12
+ if(jsonParams['PaySystems'] != nil)
13
+ @PaySystems = []
14
+ jsonParams['PaySystems'].each do |value|
15
+ @PaySystems.push(PaySystem.new(value))
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ # Payment systems list
22
+ attr_accessor :PaySystems
23
+
24
+ # Link to the license agreement, that buyer must to agree
25
+ attr_accessor :TermToUse
26
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'resp_common_object'
2
+
3
+ class RespPaymentStatus < RespCommonObject
4
+
5
+ #Order id in merchant's system
6
+ attr_accessor :MerchantInternalPaymentId
7
+
8
+ #User id in merchant's system
9
+ attr_accessor :MerchantInternalUserId
10
+
11
+ #Order sum
12
+ attr_accessor :Sum
13
+
14
+ #Custom info like comments, etc
15
+ attr_accessor :CustomMerchantInfo
16
+
17
+ attr_accessor :Signature
18
+
19
+ def initialize(jsonParams)
20
+ if (jsonParams != nil)
21
+ @MerchantInternalPaymentId = jsonParams['MerchantInternalPaymentId']
22
+ @MerchantInternalUserId = jsonParams['MerchantInternalUserId']
23
+ @Sum = jsonParams['Sum']
24
+ @CustomMerchantInfo = jsonParams['CustomMerchantInfo']
25
+ @Signature = jsonParams['Signature']
26
+ @ErrorCode = jsonParams['ErrorCode']
27
+ @DebugMessage = jsonParams['DebugMessage']
28
+ end
29
+ end
30
+
31
+ def ValidateSignature?()
32
+ signature = Md5Helper.GetMd5FromString(
33
+ @ErrorCode +
34
+ @MerchantInternalPaymentId ||= '' +
35
+ @MerchantInternalUserId ||= '' +
36
+ format('%.2f', @Sum) +
37
+ @CustomMerchantInfo ||= '' +
38
+ KaznacheyConfigurations.MerchantSecretKey.upcase
39
+ );
40
+
41
+ signature == @Signature
42
+ end
43
+ end
@@ -0,0 +1,9 @@
1
+ class KaznacheyConfigurations
2
+ cattr_accessor :MerchantGuid
3
+
4
+ cattr_accessor :MerchantSecretKey
5
+
6
+ cattr_accessor :ServerUrl
7
+ @@ServerUrl = 'http://payment.kaznachey.net/api/PaymentInterface/'
8
+
9
+ end
@@ -0,0 +1,26 @@
1
+ #require 'json'
2
+ require 'net/http'
3
+ require 'active_support'
4
+ require 'ApiObjects/kaznachey_configurations'
5
+
6
+ class HttpHelper
7
+ def self.SendRequest(request, uri)
8
+
9
+ uri = URI.parse(KaznacheyConfigurations.ServerUrl + uri)
10
+ begin
11
+ header = {'Content-Type' => 'text/json'}
12
+ http = Net::HTTP.new(uri.host, uri.port)
13
+ httpRequest = Net::HTTP::Post.new(uri.request_uri, header)
14
+ body = ActiveSupport::JSON.encode(request)
15
+ httpRequest.body = body
16
+
17
+ response = http.request(httpRequest)
18
+
19
+ response.body
20
+ rescue
21
+
22
+ ensure
23
+ nil
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ require 'digest/md5'
2
+
3
+ class Md5Helper
4
+ def self.GetMd5FromString(string)
5
+ Digest::MD5.hexdigest(string)
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module KaznacheyPayments
2
+ VERSION = "0.9.7.7"
3
+ end
@@ -0,0 +1,32 @@
1
+ # Gem was created for creating payments with Kaznachey platform.
2
+ # All requests and responses are used json encoding and sent via POST
3
+ # More information you can find on our website https://kaznachey.ua/
4
+
5
+ require 'Helpers/http_helper'
6
+ require 'active_support'
7
+ require 'ApiObjects/Responses/resp_merchant_info'
8
+ require 'ApiObjects/Responses/resp_create_payment'
9
+
10
+ # Main class for interaction with api
11
+ class KaznacheyPaymentsApi
12
+
13
+ # GetMerchantInfo method retrieves a list of payment systems accessible for merchant.
14
+ # Request class - ReqGetMerchantInfo
15
+ # Response class - RespMerchantInfo
16
+ def GetMerchantInfo(request)
17
+ request.GenerateSign()
18
+ response = HttpHelper.SendRequest(request, 'GetMerchatInformation')
19
+
20
+ responseObject = RespMerchantInfo.new(ActiveSupport::JSON.decode(response))
21
+ end
22
+
23
+ # GetMerchantInfo method allow to create payment.
24
+ # Request class - ReqGetMerchantInfo
25
+ # Response class - RespMerchantInfo
26
+ def CreatePayment(request)
27
+ request.GenerateSign()
28
+ response = HttpHelper.SendRequest(request, 'CreatePayment')
29
+
30
+ responseObject = RespCreatePayment.new(ActiveSupport::JSON.decode(response))
31
+ end
32
+ end
@@ -0,0 +1,55 @@
1
+ require 'minitest/autorun'
2
+ require 'kaznachey_payments_api'
3
+ require 'ApiObjects/kaznachey_configurations'
4
+ require 'ApiObjects/Requests/req_get_merchant_info'
5
+ require 'ApiObjects/Requests/req_create_payment'
6
+ require 'ApiObjects/Requests/payment_details'
7
+ require 'ApiObjects/Requests/product'
8
+
9
+ class GetMerchantInfo < MiniTest::Unit::TestCase
10
+ def test_GetInfo
11
+ KaznacheyConfigurations.MerchantGuid = 'F33AC643-0847-4174-9E72-65FEE9563AD7'
12
+ KaznacheyConfigurations.MerchantSecretKey = '253A65F6-4CD5-4EA7-AF09-9F6485592D7F'
13
+
14
+ api = KaznacheyPaymentsApi.new
15
+
16
+ request = ReqGetMerchantInfo.new
17
+
18
+ request.MerchantGuid = KaznacheyConfigurations.MerchantGuid
19
+
20
+ response = api.GetMerchantInfo(request)
21
+
22
+ assert_equal(0, response.ErrorCode)
23
+ end
24
+
25
+ def test_CreatePayment
26
+ KaznacheyConfigurations.MerchantGuid = 'F33AC643-0847-4174-9E72-65FEE9563AD7'
27
+ KaznacheyConfigurations.MerchantSecretKey = '253A65F6-4CD5-4EA7-AF09-9F6485592D7F'
28
+
29
+ api = KaznacheyPaymentsApi.new
30
+
31
+ request = ReqCreatePayment.new
32
+ request.MerchantGuid = KaznacheyConfigurations.MerchantGuid
33
+ request.SelectedPaySystemId = 1
34
+
35
+ paymentDetails = PaymentDetails.new
36
+ paymentDetails.PhoneNumber = '123123123'
37
+ paymentDetails.EMail = 'email@email.com'
38
+ paymentDetails.MerchantInternalPaymentId = '0'
39
+ paymentDetails.BuyerFirstname = 'Test'
40
+ request.PaymentDetails = paymentDetails
41
+
42
+
43
+ product = Product.new
44
+ product.ProductId = '1'
45
+ product.ProductItemsNum = 1
46
+ product.ProductName = 'Test Item'
47
+ product.ProductPrice = 1
48
+ request.Products = [ product ]
49
+ request
50
+
51
+ response = api.CreatePayment(request)
52
+
53
+ assert_equal(0, response.ErrorCode)
54
+ end
55
+ end