paygate-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,25 @@
1
+ module Paygate
2
+ class Response
3
+ attr_accessor :transaction_type, :http_code, :message, :body, :json
4
+
5
+ def self.build_from_net_http_response(txn_type, response)
6
+ r = new
7
+ r.transaction_type = txn_type
8
+ r.http_code = response.code
9
+ r.message = response.message
10
+ r.body = response.body
11
+
12
+ case txn_type
13
+ when :cancel
14
+ r.json = JSON.parse response.body.gsub(/^callback\((.*)\)$/, '\1') if response.code.to_i == 200
15
+ when :profile_pay
16
+ r.json = {}
17
+ response.body.split('&').each do |key_value_pair|
18
+ key_value_ary = key_value_pair.split('=')
19
+ r.json[key_value_ary[0]] = key_value_ary[1]
20
+ end
21
+ end
22
+ r
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,35 @@
1
+ require 'digest'
2
+ require 'uri'
3
+ require 'net/http'
4
+
5
+ module Paygate
6
+ class Transaction
7
+ CANCEL_API_URL = 'https://service.paygate.net/service/cancelAPI.json'.freeze
8
+
9
+ attr_reader :tid
10
+ attr_accessor :member
11
+
12
+ def initialize(tid)
13
+ @tid = tid
14
+ end
15
+
16
+ def cancel(options = {})
17
+ # Encrypt data
18
+ api_key_256 = ::Digest::SHA256.hexdigest(member.secret)
19
+ aes_ctr = AesCtr.encrypt(tid, api_key_256, 256)
20
+ tid_enc = "AES256#{aes_ctr}"
21
+
22
+ # Prepare params
23
+ params = { callback: 'callback', mid: member.mid, tid: tid_enc }
24
+ params.merge!(options.slice(:amount))
25
+ params.delete_if { |_, v| v.blank? }
26
+
27
+ # Make request
28
+ uri = URI(CANCEL_API_URL)
29
+ uri.query = ::URI.encode_www_form(params)
30
+ response = ::Net::HTTP.get_response(uri)
31
+
32
+ Response.build_from_net_http_response(:cancel, response)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ module Paygate
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "paygate/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "paygate-ruby"
8
+ spec.version = Paygate::VERSION
9
+ spec.authors = ["jagdeepsingh"]
10
+ spec.email = ["jagdeepsingh.125k@gmail.com"]
11
+
12
+ spec.summary = 'Ruby wrapper for PayGate payment gateway'
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.15"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,81 @@
1
+ window.Paygate = (function() {
2
+ function Paygate() {}
3
+
4
+ Paygate.fieldsMap = {
5
+ mid: 'mid',
6
+ locale: 'langcode',
7
+ charset: 'charset',
8
+ title: 'goodname',
9
+ currency: 'goodcurrency',
10
+ amount: 'unitprice',
11
+ payMethod: 'paymethod',
12
+ customerName: 'receipttoname',
13
+ customerEmail: 'receipttoemail',
14
+ cardNumber: 'cardnumber',
15
+ expiryYear: 'cardexpireyear',
16
+ expiryMonth: 'cardexpiremonth',
17
+ cvv: 'cardsecretnumber',
18
+ cardAuthCode: 'cardauthcode',
19
+ responseCode: 'replycode',
20
+ responseMessage: 'replyMsg',
21
+ tid: 'tid',
22
+ profileNo: 'profile_no',
23
+ hashResult: 'hashresult'
24
+ };
25
+
26
+ Paygate.openPayApiForm = function() {
27
+ return document.querySelector('form[name=PGIOForm]');
28
+ };
29
+
30
+ Paygate.openPayApiScreen = function() {
31
+ return document.querySelector('#PGIOscreen');
32
+ };
33
+
34
+ Paygate.openPayApiFields = function() {
35
+ var formChildren = Array.from(this.openPayApiForm().children);
36
+ return formChildren.filter(function(el) {
37
+ return el.tagName === 'INPUT';
38
+ });
39
+ }
40
+
41
+ Paygate.findInputByName = function(name) {
42
+ var mappedName = this.fieldsMap[name];
43
+ return this.openPayApiFields().filter(function(el) {
44
+ return el.name === mappedName;
45
+ })[0];
46
+ };
47
+
48
+ Paygate.cardAuthCode = function() {
49
+ return this.findInputByName('cardAuthCode').value;
50
+ };
51
+
52
+ Paygate.responseCode = function() {
53
+ return this.findInputByName('responseCode').value;
54
+ };
55
+
56
+ Paygate.responseMessage = function() {
57
+ return this.findInputByName('responseMessage').value;
58
+ };
59
+
60
+ Paygate.tid = function() {
61
+ return this.findInputByName('tid').value;
62
+ };
63
+
64
+ Paygate.profileNo = function() {
65
+ return this.findInputByName('profileNo').value;
66
+ };
67
+
68
+ Paygate.hashResult = function() {
69
+ return this.findInputByName('hashResult').value;
70
+ };
71
+
72
+ Paygate.fillInput = function(field, value) {
73
+ this.findInputByName(field).value = value;
74
+ };
75
+
76
+ Paygate.submitForm = function() {
77
+ doTransaction(document.PGIOForm);
78
+ };
79
+
80
+ return Paygate;
81
+ })();
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paygate-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jagdeepsingh
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description:
42
+ email:
43
+ - jagdeepsingh.125k@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - data/config.yml
57
+ - lib/paygate-ruby.rb
58
+ - lib/paygate/aes.rb
59
+ - lib/paygate/aes_ctr.rb
60
+ - lib/paygate/helpers/form_helper.rb
61
+ - lib/paygate/member.rb
62
+ - lib/paygate/profile.rb
63
+ - lib/paygate/response.rb
64
+ - lib/paygate/transaction.rb
65
+ - lib/paygate/version.rb
66
+ - paygate-ruby.gemspec
67
+ - vendor/assets/javascripts/paygate.js
68
+ homepage:
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubyforge_project:
88
+ rubygems_version: 2.6.11
89
+ signing_key:
90
+ specification_version: 4
91
+ summary: Ruby wrapper for PayGate payment gateway
92
+ test_files: []