From ba0b72edfe4fd68528b2be6b128312c3e2a91993 Mon Sep 17 00:00:00 2001 From: shields Date: Fri, 13 May 2022 22:42:47 +0900 Subject: [PATCH 1/2] Remove cruft, add TableCheck attribution --- CODE_OF_CONDUCT.md | 74 ---------------------------------- Gemfile | 1 - LICENSE.txt | 2 +- README.md | 98 +++++++++++++++++++--------------------------- Rakefile | 4 +- bin/console | 14 ------- bin/setup | 8 ---- 7 files changed, 44 insertions(+), 157 deletions(-) delete mode 100644 CODE_OF_CONDUCT.md delete mode 100755 bin/console delete mode 100755 bin/setup diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 61f192a..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,74 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and -our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. - -## Our Standards - -Examples of behavior that contributes to creating a positive environment -include: - -* Using welcoming and inclusive language -* Being respectful of differing viewpoints and experiences -* Gracefully accepting constructive criticism -* Focusing on what is best for the community -* Showing empathy towards other community members - -Examples of unacceptable behavior by participants include: - -* The use of sexualized language or imagery and unwelcome sexual attention or -advances -* Trolling, insulting/derogatory comments, and personal or political attacks -* Public or private harassment -* Publishing others' private information, such as a physical or electronic - address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Our Responsibilities - -Project maintainers are responsible for clarifying the standards of acceptable -behavior and are expected to take appropriate and fair corrective action in -response to any instances of unacceptable behavior. - -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, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. - -## Scope - -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at jagdeep.singh@vinsol.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. - -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] - -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ diff --git a/Gemfile b/Gemfile index cdffe12..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,3 @@ source "https://rubygems.org" -# Specify your gem's dependencies in paygate-ruby.gemspec gemspec diff --git a/LICENSE.txt b/LICENSE.txt index f175add..a6aa775 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2017 jagdeepsingh +Copyright (c) 2017 Jagdeep Singh and TableCheck Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2045b41..cf27ba9 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # paygate-ruby -`paygate-ruby` is a simple Ruby wrapper for [PayGate payment gateway](http://www.paygate.net/)'s OpenPayAPI. +`paygate-ruby` is a simple Ruby wrapper for [PayGate Korean payment gateway](http://www.paygate.net/)'s OpenPayAPI. ## Installation @@ -10,14 +10,6 @@ Add this line to your application's Gemfile: gem 'paygate-ruby' ``` -And then execute: - - $ bundle - -Or install it yourself as: - - $ gem install paygate-ruby - ## Configuration You can pass a block to the `configure` method to make changes to the `Paygate` configuration. @@ -32,22 +24,24 @@ Default value for `mode` is `:live`. It uses different API urls in different mod ## Usage -To start making the transactions on PayGate, you will need a Member ID and a Secret, for which you can register [here](https://admin.paygate.net/front/regist/registMember.jsp?lang=us). +To start making the transactions on PayGate, you will need a Member ID and a Secret, +for which you can register [here](https://admin.paygate.net/front/regist/registMember.jsp?lang=us). After a successful registration, you will have access to the [dashboard](https://admin.paygate.net/front/board/welcome.jsp). -NOTE: Unless otherwise stated, all the following documentation is for making payments with Korean local credit cards in currency 'WON'. +NOTE: Unless otherwise stated, all the following documentation is for making payments +with Korean local credit cards in currency 'WON'. Contents: -- [1 Purchase](#1-purchase) -- [2 Verify](#2-verify) -- [3 Refund](#3-refund) -- [4 Profile Pay](#4-profile-pay) -- [5 JavaScript helpers](#5-javascript-helpers) +- [1. Purchase](#1-purchase) +- [2. Verify](#2-verify) +- [3. Refund](#3-refund) +- [4. Profile Pay](#4-profile-pay) +- [5. JavaScript helpers](#5-javascript-helpers) -### 1 Purchase +### 1. Purchase -#### 1.1 Include JavaScript +#### 1.1. Include JavaScript Include the _OpenPayAPI.js_ in `` of your payment page. @@ -116,10 +110,10 @@ Use `Paygate.mapped_locale` to get the locale in correct format for the form inp ```ruby Paygate.mapped_locale(:en) - => 'US' +#=> 'US' Paygate.mapped_locale('ko') - => 'KR' +#=> 'KR' ``` Valid inputs are "en", "en-US", "ko", "ko-KR", "ja", "zh-CN" and their symbolized versions. Passing `nil` would return default locale i.e. "US". @@ -130,10 +124,10 @@ Use `Paygate.mapped_currency` to get the currency in the correct format. ```ruby Paygate.mapped_currency('USD') - => 'USD' +#=> 'USD' Paygate.mapped_currency('KRW') - => 'WON' +#=> 'WON' ``` Passing `nil` above would return default currency i.e. "WON". @@ -164,7 +158,7 @@ In case of failure, you can see the error message returned by the API here. If Profile Payment Service is enabled on your Member ID, then you will get a subscription ID for customer in this field. You can use this `profile_no` to make payments for the same customer in future. -#### 1.3 Response screen +#### 1.3. Response screen You also need to add a screen at the same HTML level as above form. OpenPayAPI popups for further authentication as well as the response from the API is displayed in this screen. @@ -172,7 +166,7 @@ You also need to add a screen at the same HTML level as above form. OpenPayAPI p = paygate_open_pay_api_screen ``` -#### 1.4 JavaScript callback +#### 1.4. JavaScript callback You also need to implement a few callbacks to handle the API response. Add these to your JavaScript. @@ -200,7 +194,7 @@ function callbackfail() { } ``` -#### 1.5 Submit the form +#### 1.5. Submit the form Now finally, lets add an event to make a call to OpenPayAPI on submit of the form. If you are using jQuery, you can do it as follows: @@ -213,7 +207,7 @@ $('form[name="PGIOForm"]').on('submit', function(event){ And, your payment form is all set to make payments. -### 2 Verify +### 2. Verify If enabled, PayGate will send a server-to-server callback on every successful transaction to the URL provided by you. The same request is sent every 5 minutes (for 10 days) until your server responds with success. @@ -224,41 +218,41 @@ So, once you receive a successful JavaScript callback (`replycode == '0000'`), t ```ruby txn = Paygate::Transaction.new('testmid_123456.654321') response = txn.verify - => # +#=> # response.transaction_type - => :verify +#=> :verify response.http_code - => "200" +#=> "200" ``` Here, _testmid_123456.654321_ is `tid` of the transaction you want to verify. -### 3 Refund +### 3. Refund Initialize a `Paygate::Member` instance using the Member ID and Secret you have. ```ruby member = Paygate::Member.new('testmid', 'secret') - => # +#=> # ``` `member` responds to methods `mid`, and `secret`. ```ruby member.mid - => "testmid" +#=> "testmid" member.secret - => "secret" +#=> "secret" ``` -#### 3.1 Full refund +#### 3.1. Full refund ```ruby response = member.refund_transaction('testmid_123456.654321') - => #"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}}, @raw_info= +#=> #"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}}, @raw_info= #> ``` @@ -266,24 +260,24 @@ response = member.refund_transaction('testmid_123456.654321') ```ruby response.transaction_type - => :refund +#=> :refund response.http_code - => "200" +#=> "200" response.json - => {"replyCode"=>"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}} +#=> {"replyCode"=>"0000", "replyMessage"=>"Response has been completed", "content"=>{"object"=>"CancelAPI tid:testmid_123456.654321 SUCCESS payRsltCode:0000"}} response.raw_info - => # +#=> # response.raw_info.request_url - => "https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F" +#=> "https://service.paygate.net/service/cancelAPI.json?callback=callback&mid=testmid&tid=AES256XQIdNnkzFwMQmhF7fuJhS3m0%0A&amount=F" ``` Apart from these it also responds to `message` and `body`. -#### 3.2 Partial refund +#### 3.2. Partial refund For partial refunds, you need to pass `amount` as an option to `refund_transaction` method along with other options. @@ -293,7 +287,7 @@ response = member.refund_transaction('testmid_123456.654321', order_id: 'ord10001') ``` -### 4 Profile Pay +### 4. Profile Pay You can use the `profile_no` returned from the OpenPayAPI after first payment by a customer to make future payments for him. @@ -301,16 +295,16 @@ You can use the `profile_no` returned from the OpenPayAPI after first payment by response = member.profile_pay('profile_1234567890', 'WON', 1000) response.transaction_type - => :profile_pay +#=> :profile_pay response.http_code - => "200" +#=> "200" response.json - => {"validecode"=>"00", "authcode"=>"12345678", "authdt"=>"20171120165728", "cardname"=>"BC \x00\x00\x00\x00", "cardnumber"=>"411111**********", "cardtype"=>"301310", "cardquota"=>"00", "cardexpiremonth"=>"11", "cardexpireyear"=>"2020", "merchantno"=>"12345678", "m_tid"=>nil, "paymethodname"=>"CARD_BASIC", "ReplyMsg"=>"\xBA\xBA\xBC\xBD\xC1\xC2\xC3\xC4 OK: 12345678", "ReplyCode"=>"0000", "receipttoname"=>"Test name\xC1\xD1\xB1\xB1\xC1\xA1", "receipttoemail"=>"dev@paygate.net", "subtotalprice"=>"1000", "transactionid"=>"testmid_123456.654321", "hashresult"=>"db1fdc6789cc8d088172b79ca680b3af8711e9fb32", "mb_serial_no"=>"\r\n"} +#=> {"validecode"=>"00", "authcode"=>"12345678", "authdt"=>"20171120165728", "cardname"=>"BC \x00\x00\x00\x00", "cardnumber"=>"411111**********", "cardtype"=>"301310", "cardquota"=>"00", "cardexpiremonth"=>"11", "cardexpireyear"=>"2020", "merchantno"=>"12345678", "m_tid"=>nil, "paymethodname"=>"CARD_BASIC", "ReplyMsg"=>"\xBA\xBA\xBC\xBD\xC1\xC2\xC3\xC4 OK: 12345678", "ReplyCode"=>"0000", "receipttoname"=>"Test name\xC1\xD1\xB1\xB1\xC1\xA1", "receipttoemail"=>"dev@paygate.net", "subtotalprice"=>"1000", "transactionid"=>"testmid_123456.654321", "hashresult"=>"db1fdc6789cc8d088172b79ca680b3af8711e9fb32", "mb_serial_no"=>"\r\n"} ``` -### 5 JavaScript helpers +### 5. JavaScript helpers `paygate-ruby` also provides a JavaScript class `Paygate` with some helper functions that can be used in your JavaScript e.g. @@ -324,20 +318,10 @@ response.json - _fillInput_ - Accepts input name (_camelCased_) and a value to set - _submitForm_ - Makes a call to PayGate API with the payment form inputs -## Development - -After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment. - -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`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). - ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/jagdeepsingh/paygate-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. +Bug reports and pull requests are welcome on GitHub at https://github.com/tablecheck/paygate-ruby. ## License The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT). - -## Code of Conduct - -Everyone interacting in the Paygate project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jagdeepsingh/paygate-ruby/blob/master/CODE_OF_CONDUCT.md). diff --git a/Rakefile b/Rakefile index 43022f7..d65c578 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,2 @@ -require "bundler/gem_tasks" -task :default => :spec +require 'bundler/gem_tasks' +task default: :spec diff --git a/bin/console b/bin/console deleted file mode 100755 index a71d8cf..0000000 --- a/bin/console +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env ruby - -require "bundler/setup" -require "paygate" - -# You can add fixtures and/or initialization code here to make experimenting -# with your gem easier. You can also use a different console, if you like. - -# (If you use this, don't forget to add pry to your Gemfile!) -# require "pry" -# Pry.start - -require "irb" -IRB.start(__FILE__) diff --git a/bin/setup b/bin/setup deleted file mode 100755 index dce67d8..0000000 --- a/bin/setup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -IFS=$'\n\t' -set -vx - -bundle install - -# Do any other automated setup that you need to do here From f0648e01df002f67546fc8c95886da3497de3b9c Mon Sep 17 00:00:00 2001 From: shields Date: Fri, 13 May 2022 23:41:44 +0900 Subject: [PATCH 2/2] - Support Ruby 3.1 - Change repo attribution to TableCheck - Add rudimentary CI test --- .github/workflows/test.yml | 25 +++++++++++++++++++++++++ CHANGELOG.md | 6 ++++++ Gemfile | 2 +- Rakefile | 1 + data/config.yml | 8 ++++---- lib/paygate-ruby.rb | 12 ++++++------ lib/paygate/version.rb | 2 +- paygate-ruby.gemspec | 30 ++++++++++++++---------------- spec/integration/paygate_spec.rb | 9 +++++++++ spec/spec_helper.rb | 10 ++++++++++ 10 files changed, 77 insertions(+), 28 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 spec/integration/paygate_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..3bac377 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,25 @@ +name: Test + +on: [push, pull_request] + +jobs: + test: + name: Unit test + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest] + ruby-version: [2.1.9, 2.2.10, 2.3.8, 2.4.6, 2.5.8, 2.6.6, 2.7.2, 3.0.1, jruby-9.1.17.0, jruby-9.2.17.0, truffleruby] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby ${{ matrix.ruby-version }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby-version }} + + - name: Install dependencies + run: bundle install + + - name: Run tests + run: bundle exec rake diff --git a/CHANGELOG.md b/CHANGELOG.md index 966ed52..48bc389 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ ## Next +## 0.1.9 - 2022-05-13 + +- [PR#6](https://github.com/jagdeepsingh/paygate-ruby/pull/6) Support Ruby 3.1. ([johnnyshields](https://github.com/johnnyshields)) +- [PR#6](https://github.com/jagdeepsingh/paygate-ruby/pull/6) Change repo attribution to TableCheck. ([johnnyshields](https://github.com/johnnyshields)) +- [PR#6](https://github.com/jagdeepsingh/paygate-ruby/pull/6) Add rudimentary CI test. ([johnnyshields](https://github.com/johnnyshields)) + ## 0.1.8 - 2020-02-11 - [PR#5](https://github.com/jagdeepsingh/paygate-ruby/pull/5) Add `verify` method to Transaction class and more meta fields to the payment form. ([jagdeepsingh](https://github.com/jagdeepsingh)) diff --git a/Gemfile b/Gemfile index b4e2a20..fa75df1 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source "https://rubygems.org" +source 'https://rubygems.org' gemspec diff --git a/Rakefile b/Rakefile index d65c578..48ec749 100644 --- a/Rakefile +++ b/Rakefile @@ -1,2 +1,3 @@ require 'bundler/gem_tasks' + task default: :spec diff --git a/data/config.yml b/data/config.yml index f63786d..135307e 100644 --- a/data/config.yml +++ b/data/config.yml @@ -1,9 +1,9 @@ --- :locales: - en: &LOCALE_US 'US' - en-US: *LOCALE_US - ko: &LOCALE_KR 'KR' - ko-KR: *LOCALE_KR + en: 'US' + en-US: 'US' + ko: 'KR' + ko-KR: 'KR' ja: 'JP' zh-CN: 'CN' diff --git a/lib/paygate-ruby.rb b/lib/paygate-ruby.rb index 5deefac..d942f16 100644 --- a/lib/paygate-ruby.rb +++ b/lib/paygate-ruby.rb @@ -1,18 +1,18 @@ -require "paygate/version" - +require 'yaml' +require 'paygate/version' require 'paygate/configuration' require 'paygate/aes' require 'paygate/aes_ctr' - require 'paygate/member' require 'paygate/response' require 'paygate/transaction' require 'paygate/profile' - -require 'paygate/helpers/form_helper' if defined? ActionView +require 'paygate/helpers/form_helper' if defined?(ActionView) module Paygate - class Engine < ::Rails::Engine; end + if defined?(Rails) + class Engine < ::Rails::Engine; end + end CONFIG = YAML.load(File.read(File.expand_path('../data/config.yml', File.dirname(__FILE__)))).freeze LOCALES_MAP = CONFIG[:locales].freeze diff --git a/lib/paygate/version.rb b/lib/paygate/version.rb index af16f96..d753433 100644 --- a/lib/paygate/version.rb +++ b/lib/paygate/version.rb @@ -1,3 +1,3 @@ module Paygate - VERSION = '0.1.8' + VERSION = '0.1.9' end diff --git a/paygate-ruby.gemspec b/paygate-ruby.gemspec index 32d1bba..a779a28 100644 --- a/paygate-ruby.gemspec +++ b/paygate-ruby.gemspec @@ -1,24 +1,22 @@ # coding: utf-8 -lib = File.expand_path("../lib", __FILE__) +lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "paygate/version" + +require 'paygate/version' Gem::Specification.new do |spec| - spec.name = "paygate-ruby" + spec.name = 'paygate-ruby' spec.version = Paygate::VERSION - spec.authors = ["jagdeepsingh"] - spec.email = ["jagdeepsingh.125k@gmail.com"] - - spec.summary = 'Ruby wrapper for PayGate payment gateway' - spec.license = "MIT" + spec.authors = ['jagdeepsingh'] + spec.email = ['jagdeepsingh.125k@gmail.com'] + spec.summary = 'Ruby wrapper for PayGate Korea payment gateway' + spec.license = 'MIT' - spec.files = `git ls-files -z`.split("\x0").reject do |f| - f.match(%r{^(test|spec|features)/}) - end - spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ["lib"] + spec.files = Dir.glob('lib/**/*') + %w[CHANGELOG.md LICENSE.txt README.md Rakefile] + spec.test_files = Dir.glob('spec/**/*') + spec.require_paths = ['lib'] - spec.add_development_dependency "bundler", "~> 1.15" - spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency 'bundler' + spec.add_development_dependency 'rake' + spec.add_development_dependency 'rspec' end diff --git a/spec/integration/paygate_spec.rb b/spec/integration/paygate_spec.rb new file mode 100644 index 0000000..3fd3deb --- /dev/null +++ b/spec/integration/paygate_spec.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +require_relative '../spec_helper' + +RSpec.describe 'basic' do + it 'can load gem' do + expect(true).to eq true + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..0603392 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +$LOAD_PATH.unshift File.dirname(__FILE__) + +require 'paygate-ruby' + +RSpec.configure do |config| + config.mock_with :rspec + config.order = 'random' +end