accepton 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: abcdeaf4b53cb5a1d1fcc6ca936f8d5830a10d43
4
+ data.tar.gz: df95703326ad1575f6eb93e2530ece5617a79fcd
5
+ SHA512:
6
+ metadata.gz: bdeb63330e0e3d50c952bef0a68db1cd1a567af4aaf58346b795d9f42431bf3ac68d09d1997c464c482a993cdd2437b2903b04cac95be529cdea1d16824591aa
7
+ data.tar.gz: 2cb78a3ed01d033011eeebb473ab52b155252ad4e2b6f1ddfe6bb1dcaf7cb6676b646c1fb2db0dc93184457a9365cb28ea216a2ee67bd664435d525acc3d306c
@@ -0,0 +1,5 @@
1
+ --no-private
2
+ --protected
3
+ --markup markdown
4
+ -
5
+ README.md
@@ -0,0 +1,13 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file. This
4
+ project adheres to [Semantic Versioning 2.0.0][semver]. Any violations of this
5
+ scheme are considered to be bugs.
6
+
7
+ [semver]: http://semver.org/spec/v2.0.0.html
8
+
9
+ ## 0.1.0 - 2015-07-20
10
+
11
+ ### Added
12
+
13
+ - Initial version.
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 AcceptOn, Inc. (https://accepton.com)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # AcceptOn
2
+
3
+ [![Build Status](https://circleci.com/gh/accepton/accepton-ruby.svg?style=shield&circle-token=76d9d3cf6e881e7a80b22cc68c223725ade7fa31)](https://circleci.com/gh/accepton/accepton-ruby)
4
+
5
+ ## Documentation
6
+
7
+ Please see the [Ruby developer documentation][rubydocs] for more information.
8
+
9
+ [rubydocs]: http://developers.accepton.com/?ruby
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'accepton'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install accepton
26
+
27
+ Then, initialize the client like so:
28
+
29
+ ```ruby
30
+ require "accepton"
31
+
32
+ client = AcceptOn::Client.new(api_key: API_KEY, environment: :staging)
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Write your code *and unit tests*
40
+ 4. Ensure all tests still pass (`bundle exec rspec`)
41
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 6. Push to the branch (`git push origin my-new-feature`)
43
+ 7. Create a new pull request
@@ -0,0 +1,26 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task test: :spec
8
+
9
+ require 'rubocop/rake_task'
10
+ RuboCop::RakeTask.new
11
+
12
+ require 'yard'
13
+ YARD::Rake::YardocTask.new
14
+
15
+ require 'yardstick/rake/measurement'
16
+ Yardstick::Rake::Measurement.new(:yardstick_measure) do |measurement|
17
+ measurement.output = 'measurement/report.txt'
18
+ end
19
+
20
+ require 'yardstick/rake/verify'
21
+ Yardstick::Rake::Verify.new do |verify|
22
+ verify.threshold = 60.0
23
+ verify.require_exact_threshold = false
24
+ end
25
+
26
+ task default: [:spec, :rubocop, :verify_measurements]
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ require File.expand_path('../lib/accepton/version', __FILE__)
3
+
4
+ Gem::Specification.new do |spec|
5
+ spec.name = 'accepton'
6
+ spec.version = AcceptOn::VERSION
7
+ spec.authors = ['AcceptOn']
8
+ spec.email = ['developers@accepton.com']
9
+
10
+ spec.summary = "AcceptOn allows you to get paid in your customer's preferred method"
11
+ spec.description = "AcceptOn allows you to get paid in your customer's preferred method"
12
+ spec.homepage = "https://developers.accepton.com"
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = %w[.yardopts CHANGELOG.md LICENSE.md README.md Rakefile accepton.gemspec]
16
+ spec.files += Dir['lib/**/*.rb']
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'hashie', '~> 3.4'
20
+ spec.add_dependency 'http', '~> 0.6.4'
21
+
22
+ spec.add_development_dependency 'bundler', '~> 1.8'
23
+ end
@@ -0,0 +1,12 @@
1
+ require 'accepton/client'
2
+ require 'accepton/error'
3
+ require 'accepton/headers'
4
+ require 'accepton/promo_code'
5
+ require 'accepton/refund'
6
+ require 'accepton/request'
7
+ require 'accepton/version'
8
+
9
+ require 'accepton/base'
10
+ require 'accepton/charge'
11
+ require 'accepton/refund'
12
+ require 'accepton/transaction_token'
@@ -0,0 +1,75 @@
1
+ require 'accepton/api/utils'
2
+
3
+ module AcceptOn
4
+ module API
5
+ module Promotion
6
+ include AcceptOn::API::Utils
7
+
8
+ # Creates a promo code on AcceptOn
9
+ #
10
+ # @api public
11
+ #
12
+ # @example Create a "20OFF" promo code for $20 off of a purchase
13
+ # create_promo_code(name: '20OFF',
14
+ # promo_type: 'amount',
15
+ # value: 20_00)
16
+ #
17
+ # @example Create a "10-percent" promo code for 10% off of a purchase
18
+ # create_promo_code(name: '10per',
19
+ # promo_type: 'percentage',
20
+ # value: '10.0')
21
+ #
22
+ # @example Create a "5dollar" promo code that reduces a purchase to $5.00
23
+ # create_promo_code(name: '5dollar',
24
+ # promo_type: 'fixed_price',
25
+ # value: 5_00)
26
+ #
27
+ # @param args [Hash]
28
+ # @option args [String] :name The promo code name, as given to customers.
29
+ # @option args [String] :promo_type The type of promo code.
30
+ # @option args [Numeric] :value The promo code amount.
31
+ #
32
+ # @raise [AcceptOn::Error] If an API error happens
33
+ # @return [AcceptOn::PromoCode] The created promo code
34
+ def create_promo_code(args = {})
35
+ perform_post_with_object('/v1/promo_codes', args, AcceptOn::PromoCode)
36
+ end
37
+
38
+ # Deletes a promo code on AcceptOn
39
+ #
40
+ # @api public
41
+ #
42
+ # @example Deletes a promo code previously retrieved by the client
43
+ # client.delete_promo_code(promo_code)
44
+ #
45
+ # @param promo_code [AcceptOn::PromoCode] The promo code to delete.
46
+ #
47
+ # @raise [AcceptOn::Error] If an API error happens
48
+ # @return [AcceptOn::PromoCode] The deleted promo code
49
+ def delete_promo_code(promo_code)
50
+ perform_delete_with_object("/v1/promo_codes/#{promo_code.original_name}",
51
+ {},
52
+ AcceptOn::PromoCode)
53
+ end
54
+
55
+ # Updates a promo code on AcceptOn
56
+ #
57
+ # @api public
58
+ #
59
+ # @example Updates a "SUMMERFUN" promo code to $20 off of a purchase
60
+ # promo_code.promo_type = 'amount'
61
+ # promo_code.value = 20_00
62
+ # client.update_promo_code(promo_code)
63
+ #
64
+ # @param promo_code [AcceptOn::PromoCode] The promo code to update.
65
+ #
66
+ # @raise [AcceptOn::Error] If an API error happens
67
+ # @return [AcceptOn::PromoCode] The updated promo code
68
+ def update_promo_code(promo_code)
69
+ perform_put_with_object("/v1/promo_codes/#{promo_code.original_name}",
70
+ promo_code.as_params,
71
+ AcceptOn::PromoCode)
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,66 @@
1
+ require 'accepton/api/utils'
2
+
3
+ module AcceptOn
4
+ module API
5
+ module Querying
6
+ include AcceptOn::API::Utils
7
+
8
+ # Retrieves a charge from the API
9
+ #
10
+ # @api public
11
+ #
12
+ # @param id [String] The charge identifier
13
+ #
14
+ # @raises [AcceptOn::Error]
15
+ # @return [AcceptOn::Charge]
16
+ def charge(id)
17
+ perform_get_with_object("/v1/charges/#{id}", {}, AcceptOn::Charge)
18
+ end
19
+
20
+ # Retrieves a page of charges from the API
21
+ #
22
+ # @api public
23
+ #
24
+ # @param args [Hash] A hash of query parameters
25
+ # @option args [DateTime, String] :end_date The latest data/time for
26
+ # the objects to be created on.
27
+ # @option args [DateTime, String] :start_date The earliest date/time for
28
+ # the objects to be created on.
29
+ # @option args [String] :order The order to sort by (asc or desc).
30
+ # @option args [String] :order_by The field to order by (e.g. created_at).
31
+ #
32
+ # @raises [AcceptOn::Error]
33
+ # @return [AcceptOn::Charge]
34
+ def charges(args = {})
35
+ perform_get_with_objects('/v1/charges', args, AcceptOn::Charge)
36
+ end
37
+
38
+ # Retrieves a promo code from AcceptOn
39
+ #
40
+ # @api public
41
+ #
42
+ # @example Retrieves the promo code with the name "20OFF"
43
+ # client.promo_code('20OFF')
44
+ #
45
+ # @param name [String] The name of the promo code to retrieve.
46
+ #
47
+ # @raise [AcceptOn::Error] If an API error happens
48
+ # @return [AcceptOn::PromoCode] The retrieved promo code
49
+ def promo_code(name)
50
+ perform_get_with_object("/v1/promo_codes/#{name}", {}, AcceptOn::PromoCode)
51
+ end
52
+
53
+ # Retrieves a transaction token from the API
54
+ #
55
+ # @api public
56
+ #
57
+ # @param id [String] The transaction token identifier
58
+ #
59
+ # @raises [AcceptOn::Error]
60
+ # @return [AcceptOn::TransactionToken]
61
+ def token(id)
62
+ perform_get_with_object("/v1/tokens/#{id}", {}, AcceptOn::TransactionToken)
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,26 @@
1
+ require 'accepton/api/utils'
2
+
3
+ module AcceptOn
4
+ module API
5
+ module Refunding
6
+ include AcceptOn::API::Utils
7
+
8
+ # Refunds a charge by the specified amount
9
+ #
10
+ # @api public
11
+ #
12
+ # @example Create a refund of $1.00 on charge chg_47ce6dacb1ec5124
13
+ # refund(amount: 1_00, charge_id: 'chg_47ce6dacb1ec5124')
14
+ #
15
+ # @param args [Hash] Attributes to set on the refund
16
+ # @option args [Integer] :amount The amount in cents to refund
17
+ # @option args [String] :charge_id The id of the charge to refund
18
+ #
19
+ # @raise [AcceptOn::Error] If an API error happens
20
+ # @return [AcceptOn::Refund]
21
+ def refund(args = {})
22
+ perform_post_with_object('/v1/refunds', args, AcceptOn::Refund)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,42 @@
1
+ require 'accepton/api/utils'
2
+
3
+ module AcceptOn
4
+ module API
5
+ module Tokenization
6
+ include AcceptOn::API::Utils
7
+
8
+ # Creates a transaction token on AcceptOn
9
+ #
10
+ # @api public
11
+ #
12
+ # @example Create a transaction token with an amount of $1.00
13
+ # create_token(amount: 1_00)
14
+ #
15
+ # @example Create a transaction token with a description
16
+ # create_token(amount: 1_00, description: 'Test')
17
+ #
18
+ # @example Create a transaction token with a description and application fee
19
+ # create_token(amount: 10_99, description: 'Test', application_fee: 99)
20
+ #
21
+ # @example Create a Paypal-specific token that pays a merchant and charges
22
+ # them an application fee
23
+ # create_token(amount: 15_00, description: 'Test', application_fee: 1_50,
24
+ # merchant_paypal_account: 'merchant@example.com')
25
+ #
26
+ # @param args [Hash] Attributes to set to the transaction token
27
+ # @option args [Integer] :amount The amount in cents of the transaction
28
+ # @option args [Integer] :application_fee The application fee to be passed on to the processor
29
+ # @option args [String] :currency The currency to charge in (default: usd)
30
+ # @option args [String] :description A description of the transaction
31
+ # @option args [String] :merchant_paypal_account The merchant's Paypal
32
+ # account when you want to pay a merchant instead of
33
+ # yourself. Can be used with an application fee.
34
+ #
35
+ # @raise [AcceptOn::Error] If an API error happens
36
+ # @return [AcceptOn::TransactionToken]
37
+ def create_token(args = {})
38
+ perform_post_with_object('/v1/tokens', args, AcceptOn::TransactionToken)
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,91 @@
1
+ require 'accepton/request'
2
+
3
+ module AcceptOn
4
+ module API
5
+ module Utils
6
+ private
7
+
8
+ # @param path [String]
9
+ # @param params [Hash]
10
+ # @param klass [Class]
11
+ #
12
+ # @return [klass]
13
+ def perform_delete_with_object(path, params, klass)
14
+ perform_request_with_object(:delete, path, params, klass)
15
+ end
16
+
17
+ # @param path [String]
18
+ # @param params [Hash]
19
+ # @param klass [Class]
20
+ #
21
+ # @return [klass]
22
+ def perform_get_with_object(path, params, klass)
23
+ perform_request_with_object(:get, path, params, klass)
24
+ end
25
+
26
+ # @param path [String]
27
+ # @param params [Hash]
28
+ # @param klass [Class]
29
+ #
30
+ # @return [Array<klass>]
31
+ def perform_get_with_objects(path, params, klass)
32
+ perform_request_with_objects(:get, path, params, klass)
33
+ end
34
+
35
+ # @param path [String]
36
+ # @param params [Hash]
37
+ # @param klass [Class]
38
+ #
39
+ # @return [klass]
40
+ def perform_post_with_object(path, params, klass)
41
+ perform_request_with_object(:post, path, params, klass)
42
+ end
43
+
44
+ # @param path [String]
45
+ # @param params [Hash]
46
+ # @param klass [Class]
47
+ def perform_put_with_object(path, params, klass)
48
+ perform_request_with_object(:put, path, params, klass)
49
+ end
50
+
51
+ # @param request_method [String, Symbol]
52
+ # @param path [String]
53
+ # @param params [Hash]
54
+ #
55
+ # @return [AcceptOn::Request]
56
+ def perform_request(request_method, path, params)
57
+ AcceptOn::Request.new(self, request_method, path, with_environment(params)).perform
58
+ end
59
+
60
+ # @param request_method [String, Symbol]
61
+ # @param path [String]
62
+ # @param params [Hash]
63
+ # @param klass [Class]
64
+ #
65
+ # @return [klass]
66
+ def perform_request_with_object(request_method, path, params, klass)
67
+ response = perform_request(request_method, path, params)
68
+ klass.new(response)
69
+ end
70
+
71
+ # @param request_method [String, Symbol]
72
+ # @param path [String]
73
+ # @param params [Hash]
74
+ # @param klass [Class]
75
+ #
76
+ # @returns [Array<klass>]
77
+ def perform_request_with_objects(request_method, path, params, klass)
78
+ perform_request(request_method, path, params)[:data].map do |element|
79
+ klass.new(element)
80
+ end
81
+ end
82
+
83
+ # @param params [Hash]
84
+ #
85
+ # @return [Hash]
86
+ def with_environment(params = {})
87
+ params.merge(environment: environment)
88
+ end
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,16 @@
1
+ module AcceptOn
2
+ class Base
3
+ # Creates a object representation of a model
4
+ #
5
+ # @api public
6
+ #
7
+ # @param args [Hash]
8
+ # @return [AcceptOn::Base]
9
+ def initialize(args = {})
10
+ args.each do |key, value|
11
+ instance_variable_set("@#{key}", value)
12
+ end
13
+ yield(self) if block_given?
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,25 @@
1
+ module AcceptOn
2
+ class Charge < Base
3
+ # @attr_reader amount [Integer] The amount charged in cents
4
+ # @attr_reader application_fee [Integer] The application fee by the
5
+ # application owner in cents
6
+ # @attr_reader currency [String] The ISO code of the currency charged
7
+ # @attr_reader description [String] The description of the charge
8
+ # @attr_reader id [String] The charge identifier
9
+ # @attr_reader metadata [Hash] Any metadata about the charge
10
+ # @attr_reader refunded [Boolean] Whether the charge has been refunded
11
+ # @attr_reader remoted_id [String] The charge identifier on the processor
12
+ # @attr_reader status [String] The status of the charge
13
+ attr_reader :amount, :application_fee, :currency, :description,
14
+ :id, :metadata, :refunded, :remote_id, :status
15
+
16
+ # The time the charge was created
17
+ #
18
+ # @api public
19
+ #
20
+ # @return [Time]
21
+ def created_at
22
+ Time.parse(@created_at).utc unless @created_at.nil?
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,45 @@
1
+ require 'accepton/api/promotion'
2
+ require 'accepton/api/querying'
3
+ require 'accepton/api/refunding'
4
+ require 'accepton/api/tokenization'
5
+
6
+ module AcceptOn
7
+ class Client
8
+ include AcceptOn::API::Promotion
9
+ include AcceptOn::API::Querying
10
+ include AcceptOn::API::Refunding
11
+ include AcceptOn::API::Tokenization
12
+
13
+ attr_accessor :api_key, :environment
14
+ attr_writer :user_agent
15
+
16
+ # Initializes a new Client object
17
+ #
18
+ # @param options [Hash]
19
+ # @return [AcceptOn::Client]
20
+ def initialize(options = {})
21
+ options.each do |key, value|
22
+ instance_variable_set("@#{key}", value)
23
+ end
24
+ set_defaults
25
+ yield(self) if block_given?
26
+ end
27
+
28
+ # @return [Boolean]
29
+ def api_key?
30
+ !!api_key
31
+ end
32
+
33
+ # @return [String]
34
+ def user_agent
35
+ @user_agent ||= "accepton-ruby/#{AcceptOn::VERSION}"
36
+ end
37
+
38
+ private
39
+
40
+ # @return [void]
41
+ def set_defaults
42
+ self.environment = :production unless environment
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,70 @@
1
+ module AcceptOn
2
+ class Error < StandardError
3
+ attr_reader :status_code
4
+
5
+ # Raised when AcceptOn returns a 4xx HTTP status code
6
+ ClientError = Class.new(self)
7
+
8
+ # Raised when AcceptOn returns a 400 HTTP status code
9
+ BadRequest = Class.new(ClientError)
10
+
11
+ # Raised when AcceptOn returns a 401 HTTP status code
12
+ Unauthorized = Class.new(ClientError)
13
+
14
+ # Raised when AcceptOn returns a 404 HTTP status code
15
+ NotFound = Class.new(ClientError)
16
+
17
+ # Raised when AcceptOn returns a 5xx HTTP status code
18
+ ServerError = Class.new(self)
19
+
20
+ # Raised when AcceptOn returns a 500 HTTP status code
21
+ InternalServerError = Class.new(ServerError)
22
+
23
+ # Raised when AcceptOn returns a 502 HTTP status code
24
+ BadGateway = Class.new(ServerError)
25
+
26
+ # Raised when AcceptOn returns a 503 HTTP status code
27
+ ServiceUnavailable = Class.new(ServerError)
28
+
29
+ # Raised when AcceptOn returns a 504 HTTP status code
30
+ GatewayTimeout = Class.new(ServerError)
31
+
32
+ ERRORS = {
33
+ 400 => AcceptOn::Error::BadRequest,
34
+ 401 => AcceptOn::Error::Unauthorized,
35
+ 404 => AcceptOn::Error::NotFound,
36
+ 500 => AcceptOn::Error::InternalServerError,
37
+ 502 => AcceptOn::Error::BadGateway,
38
+ 503 => AcceptOn::Error::ServiceUnavailable,
39
+ 504 => AcceptOn::Error::GatewayTimeout
40
+ }
41
+
42
+ class << self
43
+ # @param response_body [Hashie::Mash]
44
+ # @param status_code [Integer]
45
+ # @return [AcceptOn::Error]
46
+ def from_response(response_body, status_code)
47
+ return unless ERRORS.key?(status_code)
48
+ error_class = ERRORS[status_code]
49
+ message = parse_error(response_body)
50
+ error_class.new(message, status_code)
51
+ end
52
+
53
+ private
54
+
55
+ def parse_error(body)
56
+ return '' if body.nil? || body.empty?
57
+
58
+ body.error.message
59
+ end
60
+ end
61
+
62
+ # @param message [String]
63
+ # @param code [Integer]
64
+ # @return [AcceptOn::Error]
65
+ def initialize(message = '', code = nil)
66
+ super(message)
67
+ @status_code = code
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,24 @@
1
+ module AcceptOn
2
+ class Headers
3
+ # @param client [AcceptOn::Client]
4
+ # @return [AcceptOn::Headers]
5
+ def initialize(client)
6
+ @client = client
7
+ end
8
+
9
+ # @return [Hash]
10
+ def request_headers
11
+ headers = {}
12
+ headers[:accept] = 'application/json'
13
+ headers[:authorization] = bearer_auth_header
14
+ headers[:user_agent] = @client.user_agent
15
+ headers
16
+ end
17
+
18
+ private
19
+
20
+ def bearer_auth_header
21
+ "Bearer #{@client.api_key}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,49 @@
1
+ require 'accepton/base'
2
+
3
+ module AcceptOn
4
+ class PromoCode < Base
5
+ # @attr_reader created_at [DateTime] The time the promo code was created.
6
+ # @attr_reader original_name [String] The original promo code name, if the
7
+ # name was modified.
8
+ # @api public
9
+ attr_reader :created_at, :original_name
10
+
11
+ # @attr_accessor name [String] The promo code as given to a customer
12
+ # @attr_accessor promo_type [String] The type of promo code. One of:
13
+ # "amount", "fixed_price", or
14
+ # "percentage".
15
+ # @attr_accessor value [Numeric] The amount of discount to apply, based on
16
+ # the type. If promo_type is "amount" or
17
+ # "fixed_price", an integer amount in
18
+ # cents. If type is "percentage", a decimal
19
+ # percentage.
20
+ # @api public
21
+ attr_accessor :name, :promo_type, :value
22
+
23
+ # Creates a hash representation of the promo code's current values
24
+ #
25
+ # @return [Hash] A hash representing the promo code.
26
+ def as_params
27
+ {name: name, promo_type: promo_type, value: value}
28
+ end
29
+
30
+ # Sets the new name of the promo code and memorizes the original
31
+ #
32
+ # @api public
33
+ #
34
+ # @param name [String] The new name to set for the promo code.
35
+ def name=(name)
36
+ @original_name ||= @name
37
+ @name = name
38
+ end
39
+
40
+ # Gets the original name of the promo code
41
+ #
42
+ # @api public
43
+ #
44
+ # @return [String] The original name for the promo code.
45
+ def original_name
46
+ @original_name || @name
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ module AcceptOn
2
+ class Refund < Base
3
+ # @attr_reader amount [Integer] The amount of the refund in cents
4
+ # @attr_reader created [DateTime] The time the refund was created
5
+ # @attr_reader currency [String] The ISO currency code of the refund
6
+ # @attr_reader id [String] The refund identifier
7
+ # @attr_reader metadata [Hash] Any metadata associated with the refund
8
+ # @attr_reader reason [String] The reason for the refund
9
+ #
10
+ # @api public
11
+ attr_reader :amount, :created, :currency, :id, :metadata, :reason
12
+ end
13
+ end
@@ -0,0 +1,54 @@
1
+ require 'addressable/uri'
2
+ require 'hashie/mash'
3
+ require 'http'
4
+ require 'accepton/headers'
5
+
6
+ module AcceptOn
7
+ class Request
8
+ URLS = {
9
+ development: 'http://checkout.accepton.dev',
10
+ staging: 'https://staging-checkout.accepton.com',
11
+ production: 'https://checkout.accepton.com'
12
+ }.freeze
13
+
14
+ attr_accessor :client, :headers, :options, :path
15
+
16
+ # @param client [AcceptOn::Client]
17
+ # @param request_method [String, Symbol]
18
+ # @param path [String]
19
+ # @param options [Hash]
20
+ # @return [Accepton::Request]
21
+ def initialize(client, request_method, path, options = {})
22
+ options = default_options.merge(options)
23
+ url = URLS[options.delete(:environment).to_sym]
24
+ @client = client
25
+ @request_method = request_method
26
+ @uri = Addressable::URI.parse(path.start_with?('http') ? path : url + path)
27
+ @options = options
28
+ @path = @uri.path
29
+ @headers = AcceptOn::Headers.new(@client).request_headers
30
+ end
31
+
32
+ # @return [Hashie::Mash] if the request reutrns a success code
33
+ # @raise [AcceptOn::Error] if the request returns a failure code
34
+ def perform
35
+ options_key = @request_method == :get ? :params : :form
36
+ response = HTTP.with(@headers).public_send(@request_method, @uri.to_s, options_key => @options)
37
+ response_body = Hashie::Mash.new(response.parse)
38
+ fail_or_return_response_body(response_body, response.code)
39
+ end
40
+
41
+ private
42
+
43
+ def fail_or_return_response_body(body, status_code)
44
+ error = AcceptOn::Error.from_response(body, status_code)
45
+ fail(error) if error
46
+ body
47
+ end
48
+
49
+ # @return [Hash]
50
+ def default_options
51
+ {environment: :production}
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,15 @@
1
+ module AcceptOn
2
+ class TransactionToken < Base
3
+ # @attr_reader amount [Integer] The amount of the transaction in cents
4
+ # @attr_reader application_fee [Integer] The amount of application fee
5
+ # @attr_reader created [DateTime] The time the transaction was created
6
+ # @attr_reader description [String] A description of the transaction
7
+ # @attr_reader id [String] The transaction identifier
8
+ # @attr_reader merchant_paypal_account [String] The merchant's Paypal
9
+ # account when you want to pay a merchant instead of
10
+ # yourself. Can be used with an application fee.
11
+ # @api public
12
+ attr_reader :amount, :application_fee, :created, :description, :id,
13
+ :merchant_paypal_account
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module AcceptOn
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: accepton
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - AcceptOn
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hashie
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: http
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.6.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.6.4
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.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ description: AcceptOn allows you to get paid in your customer's preferred method
56
+ email:
57
+ - developers@accepton.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".yardopts"
63
+ - CHANGELOG.md
64
+ - LICENSE.md
65
+ - README.md
66
+ - Rakefile
67
+ - accepton.gemspec
68
+ - lib/accepton.rb
69
+ - lib/accepton/api/promotion.rb
70
+ - lib/accepton/api/querying.rb
71
+ - lib/accepton/api/refunding.rb
72
+ - lib/accepton/api/tokenization.rb
73
+ - lib/accepton/api/utils.rb
74
+ - lib/accepton/base.rb
75
+ - lib/accepton/charge.rb
76
+ - lib/accepton/client.rb
77
+ - lib/accepton/error.rb
78
+ - lib/accepton/headers.rb
79
+ - lib/accepton/promo_code.rb
80
+ - lib/accepton/refund.rb
81
+ - lib/accepton/request.rb
82
+ - lib/accepton/transaction_token.rb
83
+ - lib/accepton/version.rb
84
+ homepage: https://developers.accepton.com
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.4.5
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: AcceptOn allows you to get paid in your customer's preferred method
108
+ test_files: []
109
+ has_rdoc: