payfort_start 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: 21a5936818d47f37354f17ab24a9844da1456fd2
4
+ data.tar.gz: 7af678b629882d5d4be4c9528c1a17a50a41da9b
5
+ SHA512:
6
+ metadata.gz: 56f81f4e54b67e62b2f8e132cc3478cc6cac42672419133080e076b335812a2c0c444ef5d04d6e6c00fb8ac9da8145a189c324fa20a65d76b9d490b3ecea9638
7
+ data.tar.gz: 35421f2a412b24dd33e9e65a0fe857a48eb0e70e9fd612d4d47fca081208539e4ea485a46c8b521ac2a923d886d4627feb974166878bbd4b101f7831c8109e74
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem "rspec"
6
+ gem "byebug"
data/Gemfile.lock ADDED
@@ -0,0 +1,44 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ payfort (0.1)
5
+ httparty (~> 0.13)
6
+ json (~> 1.8)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ byebug (3.5.1)
12
+ columnize (~> 0.8)
13
+ debugger-linecache (~> 1.2)
14
+ slop (~> 3.6)
15
+ columnize (0.9.0)
16
+ debugger-linecache (1.2.0)
17
+ diff-lcs (1.2.5)
18
+ httparty (0.13.5)
19
+ json (~> 1.8)
20
+ multi_xml (>= 0.5.2)
21
+ json (1.8.3)
22
+ multi_xml (0.5.5)
23
+ rspec (3.3.0)
24
+ rspec-core (~> 3.3.0)
25
+ rspec-expectations (~> 3.3.0)
26
+ rspec-mocks (~> 3.3.0)
27
+ rspec-core (3.3.2)
28
+ rspec-support (~> 3.3.0)
29
+ rspec-expectations (3.3.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.3.0)
32
+ rspec-mocks (3.3.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.3.0)
35
+ rspec-support (3.3.0)
36
+ slop (3.6.0)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ byebug
43
+ payfort!
44
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Payfort
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,95 @@
1
+ # Start Ruby
2
+
3
+ Payfort Start makes accepting payments in the Middle East ridiculously easy. Sign up for an account at [start.payfort.com](https://start.payfort.com).
4
+
5
+ ## Getting Started
6
+
7
+ Using Start with your Ruby project is simple. If you're using [bundler](http://bundler.io) (and really, who isn't these days amirite?), you just need to add one line to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem 'payfort_start', require: 'start'
11
+ ```
12
+
13
+ Now, running `bundle install` will pull the library directly to your local project.
14
+
15
+ ## Using Start
16
+
17
+ You'll need an account with Start if you don't already have one (grab one real quick at [start.payfort.com](https://start.payfort.com) and come back .. we'll wait).
18
+
19
+ Got an account? Great .. let's get busy.
20
+
21
+ ### 1. Initializing Start
22
+
23
+ To get started, you'll need to initialize Start with your secret API key. Here's how that looks (we're using a test key, so no real money will be exchanging hands):
24
+
25
+ ```ruby
26
+ require 'start'
27
+
28
+ Start.api_key = "test_sec_k_25dd497d7e657bb761ad6"
29
+ ```
30
+
31
+ That's it! You probably want to do something with the Start object though -- it gets really bored when it doesn't have anything to do.
32
+
33
+ Let's run a transaction, shall we.
34
+
35
+ ### 2. Processing a transaction through Start
36
+
37
+ Now, for the fun part. Here's all the code you need to process a transaction with Start:
38
+
39
+ ```ruby
40
+ Start::Charge.create(
41
+ :amount => 5,
42
+ :currency => "aed",
43
+ :email => "customer@example.com",
44
+ :card => {
45
+ :number => "4242424242424242",
46
+ :exp_month => 11,
47
+ :exp_year => 2016,
48
+ :cvv => 123
49
+ },
50
+ :description => "2kg of lizard tails, non-refundable"
51
+ )
52
+ ```
53
+
54
+ This transaction should be successful since we used the `4242 4242 4242 4242` test credit card. For a complete list of test cards, and their expected output you can check out this link [here](https://docs.start.payfort.com/testing/).
55
+
56
+ How can you tell that it was successful? Well, if no exception is raised then you're in the clear.
57
+
58
+ ### 3. Handling Errors
59
+
60
+ Any errors that may occur during a transaction is raised as an Exception. Here's an example of how you can handle errors with Start:
61
+
62
+ ```ruby
63
+ begin
64
+ # Use Start's bindings...
65
+
66
+ rescue Start::BankingError => e
67
+ # Since it's a decline, Start::BankingError will be caught
68
+ puts "Status is: #{e.http_status}"
69
+ puts "Code is: #{e.code}"
70
+ puts "Message is: #{e.message}"
71
+
72
+ rescue Start::RequestError => e
73
+ # Invalid parameters were supplied to Start's API
74
+
75
+ rescue Start::AuthenticationError => e
76
+ # There's something wrong with that API key you passed
77
+
78
+ rescue Start::ProcessingError => e
79
+ # There's something wrong on Start's end
80
+
81
+ rescue Start::StartError => e
82
+ # Display a very generic error to the user, and maybe send
83
+ # yourself an email
84
+
85
+ rescue => e
86
+ # Something else happened, completely unrelated to Start
87
+ end
88
+ ```
89
+
90
+ ## Testing Start
91
+ If you're looking to contribute to Start, then grab this repo and run `rake` on your local machine to run the unit tests.
92
+
93
+ ## Contributing
94
+
95
+ Read our [Contributing Guidelines](CONTRIBUTING.md) for details
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => [:test]
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.pattern = './spec/**/*_spec.rb'
8
+ end
@@ -0,0 +1,92 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIGCDCCA/CgAwIBAgIQKy5u6tl1NmwUim7bo3yMBzANBgkqhkiG9w0BAQwFADCB
3
+ hTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G
4
+ A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNV
5
+ BAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdH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7usQWxH
87
+ YINRsPkyPef89iYTx4AWpb9a/IfPeHmJIZriTAcKhjW88t5RxNKWt9x+Tu5w/Rw5
88
+ 6wwCURQtjr0W4MHfRnXnJK3s9EK0hZNwEGe6nQY1ShjTK3rMUUKhemPR5ruhxSvC
89
+ Nr4TDea9Y355e6cJDUCrat2PisP29owaQgVR1EX1n6diIWgVIEM8med8vSTYqZEX
90
+ c4g/VhsxOBi0cQ+azcgOno4uG+GMmIPLHzHxREzGBHNJdmAPx/i9F4BrLunMTA5a
91
+ mnkPIAou1Z5jJh5VkpTYghdae9C8x49OhgQ=
92
+ -----END CERTIFICATE-----
data/lib/start.rb ADDED
@@ -0,0 +1,21 @@
1
+ require "httparty"
2
+ require "start/base_resource"
3
+ require "start/customer"
4
+ require "start/charge"
5
+ require "start/errors/payfort_error"
6
+ require "start/errors/authentication_error"
7
+ require "start/errors/banking_error"
8
+ require "start/errors/request_error"
9
+ require "start/errors/processing_error"
10
+
11
+ module Start
12
+ include HTTParty
13
+
14
+ base_uri 'https://api.start.payfort.com'
15
+
16
+ ssl_ca_file File.dirname(__FILE__) + '/data/ssl-bundle.crt'
17
+
18
+ def self.api_key=(value)
19
+ default_options[:basic_auth] = {username: value, password: ''}
20
+ end
21
+ end
@@ -0,0 +1,48 @@
1
+ module Start
2
+ class BaseResource
3
+ class << self
4
+ attr_accessor :path
5
+
6
+ def create(params = {})
7
+ handle_response Start.post(path, body: params)
8
+ end
9
+
10
+ def get(id)
11
+ handle_response Start.post("#{path}/#{id}")
12
+ end
13
+
14
+ def all
15
+ handle_response Start.get(path)
16
+ end
17
+
18
+ private
19
+
20
+ def handle_response(response)
21
+ body = JSON.parse(response.body);
22
+
23
+ if response.code.between?(200, 299) and !body.key?('error')
24
+ # The request was successful
25
+ return body
26
+ end
27
+
28
+ # There was an error .. check the response
29
+ case body['error']['type']
30
+ when 'banking'
31
+ raise Start::BankingError.new(body['error']['message'], body['error']['code'], response.code)
32
+
33
+ when 'authentication'
34
+ raise Start::AuthenticationError.new(body['error']['message'], body['error']['code'], response.code)
35
+
36
+ when 'processing'
37
+ raise Start::ProcessingError.new(body['error']['message'], body['error']['code'], response.code)
38
+
39
+ when 'request'
40
+ raise Start::RequestError.new(body['error']['message'], body['error']['code'], response.code)
41
+ end
42
+
43
+ # Otherwise, raise a General error
44
+ raise Start::StartError.new(body['error']['message'], body['error']['code'], response.code)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module Start
2
+ class Charge < BaseResource
3
+ self.path = '/charges'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Start
2
+ class Customer < BaseResource
3
+ self.path = '/customers'
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Start
2
+ class AuthenticationError < StartError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Start
2
+ class BankingError < StartError
3
+ end
4
+ end
@@ -0,0 +1,18 @@
1
+ module Start
2
+ class StartError < StandardError
3
+ attr_reader :message
4
+ attr_reader :code
5
+ attr_reader :http_status
6
+
7
+ def initialize(message=nil, code=nil, http_status=nil)
8
+ @message = message
9
+ @code = code
10
+ @http_status = http_status
11
+ end
12
+
13
+ def to_s
14
+ status_string = @http_status.nil? ? "" : "(#{@code}Error - Status #{@http_status}) "
15
+ "#{status_string}#{@message}"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Start
2
+ class ProcessingError < StartError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Start
2
+ class RequestError < StartError
3
+ end
4
+ end
@@ -0,0 +1,3 @@
1
+ module Start
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,21 @@
1
+ $:.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
+
3
+ require 'start/version'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = 'payfort_start'
7
+ s.version = Start::VERSION
8
+ s.summary = 'Ruby bindings for the Payfort Start API'
9
+ s.description = 'Payfort Start is the easiest way to accept payments online in the middle east. See https://start.payfort.com for details.'
10
+ s.authors = ['Pavel Gabriel','Yazin Alirhayim']
11
+ s.email = ['pavel@payfort.com','yazin@payfort.com']
12
+ s.homepage = 'https://start.payfort.com/docs/'
13
+ s.license = 'MIT'
14
+
15
+ s.add_dependency('httparty', '~> 0.13')
16
+ s.add_dependency('json', '~> 1.8')
17
+
18
+ s.files = `git ls-files`.split("\n")
19
+ s.test_files = `git ls-files -- spec/*`.split("\n")
20
+ s.require_paths = ['lib']
21
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe Start::Charge do
4
+ before do
5
+ Start.api_key = "test_sec_k_2b99b969196bece8fa7fd"
6
+ end
7
+
8
+ it "must create a new charge" do
9
+ response = Start::Charge.create(
10
+ :amount => 400,
11
+ :currency => "usd",
12
+ :email => "ahmed@example.com",
13
+ :card => {
14
+ :name => "Abdullah Ahmed",
15
+ :number => "4242424242424242",
16
+ :exp_month => 11,
17
+ :exp_year => 2016,
18
+ :cvc => 123
19
+ },
20
+ :description => "Charge for test@example.com"
21
+ )
22
+
23
+ expect(response['captured_amount']).to eq(400)
24
+ end
25
+
26
+ it "must list created charges" do
27
+ response = Start::Charge.all()
28
+
29
+ expect(response).to_not be_empty
30
+ end
31
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Start::Customer do
4
+ before do
5
+ Start.api_key = "test_sec_k_2b99b969196bece8fa7fd"
6
+ end
7
+
8
+ it "must create a new customer" do
9
+ response = Start::Customer.create(
10
+ :name => "Abdullah Ahmed",
11
+ :email => "abdullah@msn.com",
12
+ :card => {
13
+ :number => "4242424242424242",
14
+ :exp_month => 11,
15
+ :exp_year => 2016,
16
+ :cvc => 123
17
+ },
18
+ :description => "Signed up at the Trade Show in Dec 2014"
19
+ )
20
+
21
+ expect(response['name']).to eq("Abdullah Ahmed")
22
+ end
23
+
24
+ it "must list created customers" do
25
+ response = Start::Customer.all()
26
+
27
+ expect(response).to_not be_empty
28
+ end
29
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Start::AuthenticationError do
4
+ it "must be thown with an invalid key" do
5
+ Start.api_key = "invalid"
6
+
7
+ expect {
8
+ response = Start::Charge.create(
9
+ :amount => 400,
10
+ :currency => "usd",
11
+ :card => {
12
+ :number => "4242424242424242",
13
+ :exp_month => 11,
14
+ :exp_year => 2016,
15
+ :cvc => 123
16
+ },
17
+ :description => "Charge for test@example.com"
18
+ )
19
+ }.to raise_error Start::AuthenticationError
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Start::BankingError do
4
+ it "must be thown with card_declined" do
5
+ Start.api_key = "test_sec_k_2b99b969196bece8fa7fd"
6
+
7
+ begin
8
+ response = Start::Charge.create(
9
+ :amount => 400,
10
+ :currency => "usd",
11
+ :email => "abdullah@msn.com",
12
+ :card => {
13
+ :name => "Abdullah Ahmed",
14
+ :number => "4000000000000002",
15
+ :exp_month => 11,
16
+ :exp_year => 2016,
17
+ :cvc => 123
18
+ },
19
+ :description => "Charge for test@example.com"
20
+ )
21
+ rescue Start::BankingError => e
22
+ expect(e.code).to eq('card_declined')
23
+ expect(e.http_status).to eq(402)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,102 @@
1
+ require 'spec_helper'
2
+
3
+ describe Start::RequestError do
4
+ before do
5
+ Start.api_key = "test_sec_k_2b99b969196bece8fa7fd"
6
+ end
7
+
8
+ it "must be thrown with invalid_cvc" do
9
+ begin
10
+ response = Start::Charge.create(
11
+ :amount => 400,
12
+ :currency => "usd",
13
+ :card => {
14
+ :number => "4242424242424242",
15
+ :exp_month => 11,
16
+ :exp_year => 2016,
17
+ :cvc => "abc"
18
+ },
19
+ :description => "Charge for test@example.com"
20
+ )
21
+ rescue Start::RequestError => e
22
+ expect(e.code).to eq('unprocessable_entity')
23
+ expect(e.http_status).to eq(422)
24
+ end
25
+ end
26
+
27
+ it "must be thown with expired_card" do
28
+ begin
29
+ response = Start::Charge.create(
30
+ :amount => 400,
31
+ :currency => "usd",
32
+ :card => {
33
+ :number => "4242424242424242",
34
+ :exp_month => 11,
35
+ :exp_year => 1999,
36
+ :cvc => 123
37
+ },
38
+ :description => "Charge for test@example.com"
39
+ )
40
+ rescue Start::RequestError => e
41
+ expect(e.code).to eq('unprocessable_entity')
42
+ expect(e.http_status).to eq(422)
43
+ end
44
+ end
45
+
46
+ it "must be thown with invalid_number" do
47
+ begin
48
+ response = Start::Charge.create(
49
+ :amount => 400,
50
+ :currency => "usd",
51
+ :card => {
52
+ :number => "1234123412341234",
53
+ :exp_month => 11,
54
+ :exp_year => 2016,
55
+ :cvc => 123
56
+ },
57
+ :description => "Charge for test@example.com"
58
+ )
59
+ rescue Start::RequestError => e
60
+ expect(e.code).to eq('unprocessable_entity')
61
+ expect(e.http_status).to eq(422)
62
+ end
63
+ end
64
+
65
+ it "must be thown with invalid_expiry_month" do
66
+ begin
67
+ response = Start::Charge.create(
68
+ :amount => 400,
69
+ :currency => "usd",
70
+ :card => {
71
+ :number => "4242424242424242",
72
+ :exp_month => 15,
73
+ :exp_year => 2016,
74
+ :cvc => 123
75
+ },
76
+ :description => "Charge for test@example.com"
77
+ )
78
+ rescue Start::RequestError => e
79
+ expect(e.code).to eq('unprocessable_entity')
80
+ expect(e.http_status).to eq(422)
81
+ end
82
+ end
83
+
84
+ it "must be thown with invalid_expiry_year" do
85
+ begin
86
+ response = Start::Charge.create(
87
+ :amount => 400,
88
+ :currency => "usd",
89
+ :card => {
90
+ :number => "4242424242424242",
91
+ :exp_month => 12,
92
+ :exp_year => "abcd",
93
+ :cvc => 123
94
+ },
95
+ :description => "Charge for test@example.com"
96
+ )
97
+ rescue Start::RequestError => e
98
+ expect(e.code).to eq('unprocessable_entity')
99
+ expect(e.http_status).to eq(422)
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,4 @@
1
+ #we need the actual library file
2
+ require_relative '../lib/start'
3
+
4
+ require 'byebug'
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: payfort_start
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Pavel Gabriel
8
+ - Yazin Alirhayim
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-08-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.13'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.13'
28
+ - !ruby/object:Gem::Dependency
29
+ name: json
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.8'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.8'
42
+ description: Payfort Start is the easiest way to accept payments online in the middle
43
+ east. See https://start.payfort.com for details.
44
+ email:
45
+ - pavel@payfort.com
46
+ - yazin@payfort.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - ".gitignore"
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - LICENSE
55
+ - README.md
56
+ - Rakefile
57
+ - lib/data/ssl-bundle.crt
58
+ - lib/start.rb
59
+ - lib/start/base_resource.rb
60
+ - lib/start/charge.rb
61
+ - lib/start/customer.rb
62
+ - lib/start/errors/authentication_error.rb
63
+ - lib/start/errors/banking_error.rb
64
+ - lib/start/errors/payfort_error.rb
65
+ - lib/start/errors/processing_error.rb
66
+ - lib/start/errors/request_error.rb
67
+ - lib/start/version.rb
68
+ - payfort_start.gemspec
69
+ - spec/lib/start/charge_spec.rb
70
+ - spec/lib/start/customer_spec.rb
71
+ - spec/lib/start/error/authentication_error_spec.rb
72
+ - spec/lib/start/error/banking_error_spec.rb
73
+ - spec/lib/start/error/request_error_spec.rb
74
+ - spec/spec_helper.rb
75
+ homepage: https://start.payfort.com/docs/
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.4.6
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Ruby bindings for the Payfort Start API
99
+ test_files:
100
+ - spec/lib/start/charge_spec.rb
101
+ - spec/lib/start/customer_spec.rb
102
+ - spec/lib/start/error/authentication_error_spec.rb
103
+ - spec/lib/start/error/banking_error_spec.rb
104
+ - spec/lib/start/error/request_error_spec.rb
105
+ - spec/spec_helper.rb