active_merchant_spgateway 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4aa4fa4a378b04baaa61715b3c66067ac0569250
4
+ data.tar.gz: a538e54742a87b6f4b90488912ebb5879c996440
5
+ SHA512:
6
+ metadata.gz: e906aac724c8dafa9ebc3203a219e7d0c52750ec8d38123f0ee2f11aa25f61a83d66065104731e0c60fc8a491ece0c95fc417cea848fc453537e5bf7d9f0da77
7
+ data.tar.gz: c2a7f3d6eeae50f74d07ae418f3eeb821283b57f20c4817a008251821883c4db55b1d3804f118ce7688286ea3d9971d081225356b4716cc466b9bf0862c6e92c
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test/tmp/*
11
+ *.gem
12
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.5
5
+ - 2.2.4
6
+ - 2.3.0
7
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_merchant_spgateway.gemspec
4
+ gemspec
5
+
6
+ group 'test' do
7
+ gem 'simplecov', require: false
8
+ gem 'minitest-reporters', require: false
9
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Gary
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # ActiveMerchantSpgateway
2
+
3
+ This gem integrate Rails with [spgateway(智付通)](https://www.spgateway.com/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'active_merchant_spgateway', github: 'afunction/active_merchant_spgateway'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```
16
+ $ bundle
17
+ ```
18
+
19
+ ## Setup
20
+
21
+ - Create file `config/initializers/spgateway.rb`
22
+ ``` sh
23
+ rails g spgateway:install
24
+ ```
25
+
26
+ - Go to spgateway and get your credential information. Then fill in `config/initializers/spgateway.rb`
27
+ ```rb
28
+ OffsitePayments::Integrations::Spgateway.setup do |spgateway|
29
+ # You have to apply credential below by yourself.
30
+ spgateway.merchant_id = '123456'
31
+ spgateway.hash_key = 'xxx'
32
+ spgateway.hash_iv = 'yyy'
33
+ end
34
+ ```
35
+
36
+ - Environment configuration:
37
+ ```rb
38
+ # config/environments/development.rb
39
+ config.after_initialize do
40
+ ActiveMerchant::Billing::Base.mode = :development
41
+ end
42
+ ```
43
+ ```rb
44
+ # config/environments/production.rb
45
+ config.after_initialize do
46
+ ActiveMerchant::Billing::Base.mode = :production
47
+ end
48
+ ```
49
+
50
+ ## Example
51
+
52
+ ```
53
+ <% payment_service_for @order,
54
+ @order.user.email,
55
+ service: :spgateway,
56
+ html: { :id => 'spgateway-form', :method => :post } do |service| %>
57
+ <% service.time_stamp @order.created_at %>
58
+ <% service.merchant_order_no @order.id %>
59
+ <% service.amt @order.total_amount.to_i %>
60
+ <% service.item_desc @order.description %>
61
+ <% service.email @order.user.email %>
62
+ <% service.login_type 0 %>
63
+ <% service.encrypted_data %>
64
+ <%= submit_tag '付款' %>
65
+ <% end %>
66
+ ```
67
+
68
+ ## License
69
+
70
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,19 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ desc "Run the unit test suite"
6
+ task :default => 'test:units'
7
+
8
+ task :test => 'test:units'
9
+
10
+ namespace :test do
11
+
12
+ Rake::TestTask.new(:units) do |t|
13
+ t.pattern = 'test/unit/**/*_test.rb'
14
+ t.ruby_opts << '-rubygems'
15
+ t.libs << 'test'
16
+ t.verbose = true
17
+ end
18
+
19
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_merchant_spgateway/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_merchant_spgateway"
8
+ spec.version = ActiveMerchantSpgateway::VERSION
9
+ spec.authors = ["Gary"]
10
+ spec.email = ["me@adz.cool"]
11
+
12
+ spec.summary = %q{spgateway (智付通) gem}
13
+ spec.description = %q{This gem integrate Rails with spgateway (智付通).}
14
+ spec.homepage = "https://github.com/imgarylai/active_merchant_spgateway"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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_dependency 'activemerchant', '~> 1.50'
23
+ spec.add_dependency 'offsite_payments', '~> 2'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.10'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rails', '>= 3.2.6', '< 5'
28
+
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "active_merchant_spgateway"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ require 'action_view'
2
+ require 'active_merchant_spgateway/version'
3
+ require 'active_merchant'
4
+ require 'offsite_payments'
5
+ require 'active_support/core_ext/string'
6
+ require 'uri'
7
+
8
+ module OffsitePayments
9
+ module Integrations
10
+ autoload :Spgateway, 'offsite_payments/integrations/spgateway'
11
+ end
12
+ end
13
+
14
+ ActionView::Base.send(:include, OffsitePayments::ActionViewHelper)
@@ -0,0 +1,3 @@
1
+ module ActiveMerchantSpgateway
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,19 @@
1
+ module Spgateway
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ desc "Creates a spgateway initialize"
7
+ class_option :orm
8
+
9
+ def copy_initializer
10
+ template "spgateway.rb", "config/initializers/spgateway.rb"
11
+ end
12
+
13
+ def show_readme
14
+ readme "README" if behavior == :invoke
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ ===============================================================================
2
+
3
+ Please check and setup your `config/initializers/spgateway.rb`
4
+
5
+ OffsitePayments::Integrations::Spgateway.setup do |spgateway|
6
+ spgateway.merchant_id =
7
+ spgateway.hash_key =
8
+ spgateway.hash_iv =
9
+ end
10
+
11
+ ===============================================================================
@@ -0,0 +1,6 @@
1
+ OffsitePayments::Integrations::Spgateway.setup do |spgateway|
2
+ # You have to apply credential below by yourself.
3
+ spgateway.merchant_id = ''
4
+ spgateway.hash_key = ''
5
+ spgateway.hash_iv = ''
6
+ end
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ require 'digest'
3
+ require File.dirname(__FILE__) + '/spgateway/helper.rb'
4
+ require File.dirname(__FILE__) + '/spgateway/notification.rb'
5
+
6
+ module OffsitePayments #:nodoc:
7
+ module Integrations #:nodoc:
8
+ module Spgateway
9
+
10
+ VERSION = '1.2'
11
+ RESPOND_TYPE = 'String'
12
+ CHECK_VALUE_FIELDS = %w(Amt MerchantID MerchantOrderNo TimeStamp Version)
13
+ CHECK_CODE_FIELDS = %w(Amt MerchantID MerchantOrderNo TradeNo)
14
+
15
+ CONFIG = %w(
16
+ MerchantID LangType TradeLimit ExpireDate NotifyURL EmailModify LoginType
17
+ )
18
+
19
+ mattr_accessor :service_url
20
+ mattr_accessor :hash_key
21
+ mattr_accessor :hash_iv
22
+ mattr_accessor :debug
23
+
24
+ CONFIG.each do |field|
25
+ mattr_accessor field.underscore.to_sym
26
+ end
27
+
28
+ def self.service_url
29
+ mode = ActiveMerchant::Billing::Base.mode
30
+ case mode
31
+ when :production
32
+ 'https://core.spgateway.com/MPG/mpg_gateway'
33
+ when :development
34
+ 'https://ccore.spgateway.com/MPG/mpg_gateway'
35
+ when :test
36
+ 'https://ccore.spgateway.com/MPG/mpg_gateway'
37
+ else
38
+ raise StandardError, "Integration mode set to an invalid value: #{mode}"
39
+ end
40
+ end
41
+
42
+ def self.notification(post)
43
+ Notification.new(post)
44
+ end
45
+
46
+ def self.setup
47
+ yield(self)
48
+ end
49
+
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,69 @@
1
+ # encoding: utf-8
2
+ require 'digest'
3
+
4
+ module OffsitePayments #:nodoc:
5
+ module Integrations #:nodoc:
6
+ module Spgateway
7
+ class Helper < OffsitePayments::Helper
8
+ FIELDS = %w(
9
+ MerchantID LangType MerchantOrderNo Amt ItemDesc TradeLimit
10
+ ExpireDate ReturnURL NotifyURL CustomerURL ClientBackURL Email
11
+ EmailModify LoginType OrderComment CREDIT CreditRed InstFlag UNIONPAY
12
+ WEBATM VACC CVS BARCODE CUSTOM TokenTerm
13
+ )
14
+
15
+ FIELDS.each do |field|
16
+ mapping field.underscore.to_sym, field
17
+ end
18
+ mapping :account, 'MerchantID' # AM common
19
+ mapping :amount, 'Amt' # AM common
20
+
21
+ # 廠商編號(由 allpay 提供)
22
+ # type: Varchar(10)
23
+ # presense: true
24
+ # example: 2000132
25
+ # description:
26
+ # mapping :merchant_id, 'MerchantID'
27
+ # mapping :account, 'MerchantID' # AM common
28
+
29
+ def initialize(order, account, options = {})
30
+ super
31
+ add_field 'Version', OffsitePayments::Integrations::Spgateway::VERSION
32
+ add_field 'RespondType', OffsitePayments::Integrations::Spgateway::RESPOND_TYPE
33
+ OffsitePayments::Integrations::Spgateway::CONFIG.each do |field|
34
+ add_field field, OffsitePayments::Integrations::Spgateway.send(field.underscore.to_sym)
35
+ end
36
+ end
37
+
38
+ def hash_key(key)
39
+ @key = key
40
+ end
41
+
42
+ def hash_iv(iv)
43
+ @iv = iv
44
+ end
45
+
46
+ def merchant_hash_key
47
+ @key || OffsitePayments::Integrations::Spgateway.hash_key
48
+ end
49
+
50
+ def merchant_hash_iv
51
+ @iv || OffsitePayments::Integrations::Spgateway.hash_iv
52
+ end
53
+
54
+ def time_stamp(date)
55
+ add_field 'TimeStamp', date.to_time.to_i
56
+ end
57
+
58
+ def encrypted_data
59
+ raw_data = URI.encode_www_form OffsitePayments::Integrations::Spgateway::CHECK_VALUE_FIELDS.sort.map { |field|
60
+ [field, @fields[field]]
61
+ }
62
+
63
+ hash_raw_data = "HashKey=#{merchant_hash_key}&#{raw_data}&HashIV=#{merchant_hash_iv}"
64
+ add_field 'CheckValue', Digest::SHA256.hexdigest(hash_raw_data).upcase
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,62 @@
1
+ # encoding: utf-8
2
+ require 'digest'
3
+
4
+ module OffsitePayments #:nodoc:
5
+ module Integrations #:nodoc:
6
+ module Spgateway
7
+ class Notification < OffsitePayments::Notification
8
+ PARAMS_FIELDS = %w(
9
+ Status Message MerchantID Amt TradeNo MerchantOrderNo PaymentType RespondType CheckCode PayTime IP
10
+ EscrowBank TokenUseStatus RespondCode Auth Card6No Card4No Inst InstFirst InstEach ECI PayBankCode
11
+ PayerAccount5Code CodeNo BankCode Barcode_1 Barcode_2 Barcode_3 ExpireDate CheckCode
12
+ )
13
+
14
+ PARAMS_FIELDS.each do |field|
15
+ define_method field.underscore do
16
+ @params[field]
17
+ end
18
+ end
19
+
20
+ def hash_key=(key)
21
+ @hash_key = key
22
+ end
23
+
24
+ def hash_iv=(iv)
25
+ @hash_iv = iv
26
+ end
27
+
28
+ def hash_key
29
+ @hash_key || OffsitePayments::Integrations::Spgateway.hash_key
30
+ end
31
+
32
+ def hash_iv
33
+ @hash_iv || OffsitePayments::Integrations::Spgateway.hash_iv
34
+ end
35
+
36
+ def success?
37
+ status == 'SUCCESS'
38
+ end
39
+
40
+ # TODO 使用查詢功能實作 acknowledge
41
+ # Spgateway 沒有遠端驗證功能,
42
+ # 而以 checksum_ok? 代替
43
+ def acknowledge
44
+ checksum_ok?
45
+ end
46
+
47
+ def complete?
48
+ %w(SUCCESS CUSTOM).include? status
49
+ end
50
+
51
+ def checksum_ok?
52
+ raw_data = URI.encode_www_form OffsitePayments::Integrations::Spgateway::CHECK_CODE_FIELDS.sort.map { |field|
53
+ [field, @params[field]]
54
+ }
55
+
56
+ hash_raw_data = "HashIV=#{hash_iv}&#{raw_data}&HashKey=#{hash_key}"
57
+ Digest::SHA256.hexdigest(hash_raw_data).upcase == check_code
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_merchant_spgateway
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gary
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemerchant
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.50'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.50'
27
+ - !ruby/object:Gem::Dependency
28
+ name: offsite_payments
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.6
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '5'
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: 3.2.6
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '5'
89
+ description: This gem integrate Rails with spgateway (智付通).
90
+ email:
91
+ - me@adz.cool
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
+ - CODE_OF_CONDUCT.md
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - active_merchant_spgateway.gemspec
104
+ - bin/console
105
+ - bin/setup
106
+ - lib/active_merchant_spgateway.rb
107
+ - lib/active_merchant_spgateway/version.rb
108
+ - lib/generators/spgateway/install_generator.rb
109
+ - lib/generators/spgateway/templates/README
110
+ - lib/generators/spgateway/templates/spgateway.rb
111
+ - lib/offsite_payments/integrations/spgateway.rb
112
+ - lib/offsite_payments/integrations/spgateway/helper.rb
113
+ - lib/offsite_payments/integrations/spgateway/notification.rb
114
+ homepage: https://github.com/imgarylai/active_merchant_spgateway
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.4.8
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: spgateway (智付通) gem
138
+ test_files: []