amplifypay_ruby 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ada543d08ed0b4791d17d2ad4359680fb93efa2
4
+ data.tar.gz: 3806d7ba20e5413e86b6cc2de12596222372372a
5
+ SHA512:
6
+ metadata.gz: bef4e01cb9ebc78945da4ee122b8aa6293c9ef536020a830a976cefef2a5f17d5e93c69a473db521184784092d7d91dcf35cc7d68005263040fb9941acb1cf4c
7
+ data.tar.gz: 0fdc33c309240781b78ab64084baec114dea10643d241ad90711f68b28465c9b96b219abad6afe91ea33670e024c1a69c7e437688fed4a8f9126bce650602b40
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ *.DS_Store
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ api_test.rb
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in amplifypay_ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Innocent
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,81 @@
1
+
2
+ # AmplifyPay Ruby Client API
3
+ ========================
4
+ AMplifyPay Payments Ruby Client Library
5
+
6
+ ## Offical Documentation
7
+ http://amplifypay.com/developers
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'amplifypay_ruby'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install amplifypay_ruby
24
+
25
+ ## Usage
26
+
27
+ ## Setup your API Keys
28
+ If you are using rails you may create an file under `RAILS_ROOT/config/initializers` and put these setting there.
29
+
30
+ AmplifypayRuby::Setup.merchant_id = "YOUR_MERCHANT_ID"
31
+ AmplifypayRuby::Setup.private_key = "YOUR_API_PRIVATE_KEY"
32
+
33
+ ## Create your Checkout Invoice
34
+
35
+ co = AmplifypayRuby::Checkout::Invoice.new
36
+
37
+ ## Set the total amount to be charged ! Important
38
+
39
+ co.total_amount = 1200.99
40
+
41
+
42
+ ## Redirecting to your checkout invoice page
43
+
44
+ if co.create
45
+ redirect_to co.invoice_url
46
+ else
47
+ @message = co.response_text
48
+ end
49
+
50
+
51
+
52
+
53
+
54
+ ## Contributing
55
+
56
+ 1. Fork it
57
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
58
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
59
+ 4. Push to the branch (`git push origin my-new-feature`)
60
+ 5. Create new Pull Request
61
+
62
+
63
+ ## License
64
+
65
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -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 'amplifypay_ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "amplifypay_ruby"
8
+ spec.version = AmplifypayRuby::VERSION
9
+ spec.authors = ["Innocent"]
10
+ spec.email = ["innocentudeh@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby library for integrating with AmplifyPay}
13
+ spec.description = %q{Ruby client bindings for the AmplifyPay API}
14
+ spec.homepage = "https://amplifypay.com/developers"
15
+ spec.license = "MIT"
16
+ spec.post_install_message = "Thanks for installing AmplifyPay Ruby client.\nYou may read full API docs at https://amplifypay.com/developers"
17
+
18
+
19
+ spec.files = `git ls-files`.split($/)
20
+ spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency('multi_json', '~> 1.10', '>= 1.10.1')
27
+ spec.add_dependency('http', '~> 2.0', '>= 2.0.3')
28
+
29
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "amplifypay_ruby"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,95 @@
1
+ module AmplifypayRuby
2
+ module Checkout
3
+ class Invoice < AmplifypayRuby::Checkout::Core
4
+
5
+ attr_accessor :order_id, :total_amount, :redirect_url, :store, :paymentDescription
6
+ attr_accessor :customer, :status_desc, :trans_id, :transaction_ref, :response_text, :invoice_url, :status_code
7
+
8
+ def initialize
9
+ @order_id = 0
10
+ @trans_id = 22
11
+ @customer = {}
12
+ @total_amount = 0.0
13
+ @redirect_url = ""
14
+ @paymentDescription = ""
15
+ end
16
+
17
+ def get_customer_info(key)
18
+ @customer["#{key}"]
19
+ end
20
+
21
+ def get_custom_data(key)
22
+ @custom_data["#{key}"]
23
+ end
24
+
25
+ def confirm(token)
26
+ verification_payload = build_verification_payload(token)
27
+ result = http_json_request(AmplifypayRuby::Setup.checkout_confirm_base_url, verification_payload)
28
+
29
+ if result["StatusDesc"] == "Approved"
30
+ # rebuild_invoice(result)
31
+ @response_text = "Payment was successful"
32
+ true
33
+ else
34
+ @status = result["status"]
35
+ @response_text = "Invoice status is #{result['StatusDesc'].upcase}"
36
+ false
37
+ end
38
+ end
39
+
40
+ def create
41
+ result = http_json_request(AmplifypayRuby::Setup.checkout_base_url,build_invoice_payload)
42
+ @store = result.inspect
43
+ create_response(result)
44
+ end
45
+
46
+ protected
47
+ def build_invoice_payload
48
+ {
49
+ merchantId: AmplifypayRuby::Setup.merchant_id,
50
+ apiKey: AmplifypayRuby::Setup.private_key,
51
+ transID: @order_id,
52
+ customerEmail: @customer["email"],
53
+ customerName: @customer["name"],
54
+ Amount: @total_amount,
55
+ redirectUrl: @redirect_url ,
56
+ paymentDescription: @paymentDescription
57
+ }
58
+ end
59
+
60
+ def build_verification_payload(token)
61
+ {
62
+ merchantId: AmplifypayRuby::Setup.merchant_id,
63
+ apiKey: AmplifypayRuby::Setup.private_key,
64
+ transactionRef: token
65
+ }
66
+
67
+ end
68
+
69
+ def rebuild_invoice(result={})
70
+
71
+ end
72
+
73
+ def create_response(result={})
74
+
75
+ if result["StatusCode"] == "000"
76
+ @status_desc = result["StatusDesc"]
77
+ @status_code = result["StatusCode"]
78
+ @trans_id = result["TransID"]
79
+ @transaction_ref = result["TransactionRef"]
80
+ @auth_token = result["AuthToken"]
81
+ @invoice_url = result["PaymentUrl"]
82
+ @status = AmplifypayRuby::SUCCESS
83
+ true
84
+ else
85
+ @status_desc = result["StatusDesc"]
86
+ @status_code = result["StatusCode"]
87
+ @invoice_url = nil
88
+ @status = AmplifypayRuby::FAIL
89
+ false
90
+ end
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,23 @@
1
+ module AmplifypayRuby
2
+ module Checkout
3
+ class Core
4
+ include AmplifypayRuby::Utilities
5
+ attr_accessor :status, :response_text, :response_code, :transaction_id, :description, :token, :result, :invoice_token
6
+
7
+ def push_results(result={})
8
+ @result = result
9
+ @transaction_id = result["transaction_id"]
10
+ @description = result["description"]
11
+ @response_code = result["response_code"]
12
+ @response_text = result["response_text"]
13
+ @token = result["token"]
14
+ @response_code == "00" ? @status = AmplifypayRuby::SUCCESS : @status = AmplifypayRuby::FAIL
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ %w(checkout/redirect_invoice
21
+ ).each do |lib|
22
+ require File.join(File.dirname(__FILE__), lib)
23
+ end
@@ -0,0 +1,34 @@
1
+ module AmplifypayRuby
2
+ module Setup
3
+ @@merchant_id = nil
4
+ @@private_key = nil
5
+ @@public_key = nil
6
+ @@token = nil
7
+ @@mode = "test"
8
+
9
+ ROOT_URL_BASE = "https://api.amplifypay.com"
10
+
11
+ LIVE_CHECKOUT_INVOICE_BASE_URL = "#{ROOT_URL_BASE}/merchant/transact"
12
+
13
+ LIVE_CHECKOUT_CONFIRM_BASE_URL = "#{ROOT_URL_BASE}/merchant/verify"
14
+
15
+
16
+ def self.merchant_id=(merchant_id); @@merchant_id = merchant_id; end
17
+ def self.merchant_id; @@merchant_id; end
18
+ def self.private_key=(private_key); @@private_key = private_key; end
19
+ def self.private_key; @@private_key; end
20
+
21
+
22
+ def self.mode=(mode); @@mode = mode; end
23
+ def self.mode; @@mode; end
24
+
25
+ def self.checkout_base_url
26
+ LIVE_CHECKOUT_INVOICE_BASE_URL
27
+ end
28
+
29
+ def self.checkout_confirm_base_url
30
+ LIVE_CHECKOUT_CONFIRM_BASE_URL
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module AmplifypayRuby
2
+ module Utilities
3
+ def http_json_request(baseurl,payload={})
4
+
5
+ result = HTTP.headers('content_typet-Type' => "application/json", 'Cache-Control'=> "no-cache").post(baseurl, :json => payload)
6
+ json_to_hash(result.to_s)
7
+ end
8
+
9
+ def http_get_request(baseurl)
10
+ end
11
+
12
+ def hash_to_json(params={})
13
+ MultiJson.dump params
14
+ end
15
+
16
+ def json_to_hash(params={})
17
+ MultiJson.load params
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module AmplifypayRuby
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,11 @@
1
+ require "amplifypay_ruby/version"
2
+ require 'multi_json'
3
+ require 'http'
4
+ require "amplifypay_ruby/setup"
5
+ require "amplifypay_ruby/utilities"
6
+ require "amplifypay_ruby/checkout"
7
+ module AmplifypayRuby
8
+ SUCCESS = "success"
9
+ FAIL = "fail"
10
+ PENDING = "pending"
11
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: amplifypay_ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Innocent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-27 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.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
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
+ - !ruby/object:Gem::Dependency
42
+ name: multi_json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 1.10.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '1.10'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 1.10.1
61
+ - !ruby/object:Gem::Dependency
62
+ name: http
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '2.0'
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: 2.0.3
71
+ type: :runtime
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: '2.0'
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: 2.0.3
81
+ description: Ruby client bindings for the AmplifyPay API
82
+ email:
83
+ - innocentudeh@gmail.com
84
+ executables:
85
+ - console
86
+ - setup
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - amplifypay_ruby.gemspec
96
+ - bin/console
97
+ - bin/setup
98
+ - lib/amplifypay_ruby.rb
99
+ - lib/amplifypay_ruby/checkout.rb
100
+ - lib/amplifypay_ruby/checkout/redirect_invoice.rb
101
+ - lib/amplifypay_ruby/setup.rb
102
+ - lib/amplifypay_ruby/utilities.rb
103
+ - lib/amplifypay_ruby/version.rb
104
+ homepage: https://amplifypay.com/developers
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message: |-
109
+ Thanks for installing AmplifyPay Ruby client.
110
+ You may read full API docs at https://amplifypay.com/developers
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.5.1
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Ruby library for integrating with AmplifyPay
130
+ test_files: []