pandapay 0.0.0.dev0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b2e4a94ec57f7268c7136aca6820d63d8aac89c
4
+ data.tar.gz: 7a5ade308a3ca2d23870258600ace0f86724880a
5
+ SHA512:
6
+ metadata.gz: 950b9e1d88ad2c8cec9c8045682b149f8c8a1c7859316470555989ce20c0118a82dcf0c958a38ff94ba8b8c2b53e0258fec6fc7e59e94d560d36e8eb6a5825c7
7
+ data.tar.gz: 69138e3c2e3e243508354cf8a61b2a4c0d7f278602873031ac00276c70871c78eca60433a85132b2a389c25cffe0a3283a894b7d51a0ba5bf6bb31664c1dce25
@@ -0,0 +1,3 @@
1
+ quit
2
+ JSON.parse(response)
3
+ response
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pandapay.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Dave Benvenuti
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.
@@ -0,0 +1,50 @@
1
+ # PandaPay Stripe Bindings
2
+
3
+ This is an early development release of the PandaPay Ruby bindings. Currently, only PandaPay Ecommerce integration with Stripe Connect is supported.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install pandapay
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ The PandaPay ECS client is meant to be a drop-in replacement for users who are already using Stripe and would now like to donate a percentage of their revenue through PandaPay ECS w/ Stripe Connect. Currently, only the Charge/Donation method is supported.
14
+
15
+ To start processing payments through PandaPay and allocate revenue to charity, this:
16
+
17
+ ```ruby
18
+ require 'stripe'
19
+
20
+ Stripe.api_key = "sk_test_mystripesecretkey"
21
+
22
+ Stripe::Charge.create(
23
+ amount: 400,
24
+ currency: "usd",
25
+ source: "tok_18An5IGxtonQ6vBUBnw2t7LQ", # obtained with Stripe.js
26
+ description: "Charge for test@example.com"
27
+ )
28
+ ```
29
+
30
+ becomes this:
31
+
32
+ ```ruby
33
+
34
+ require 'pandapay'
35
+
36
+ PandaPay.api_key = "sk_test_myPANDAsecretkey"
37
+
38
+ PandaPay::StripeEcommerce::Charge.create(
39
+ amount: 400,
40
+ donation_amount: 100,
41
+ receipt_email: thedonator@email.com,
42
+ destination_ein: "12-3456789", # Optional
43
+ currency: "usd",
44
+ source: "tok_18An5IGxtonQ6vBUBnw2t7LQ", # still the same token from Stripe.js
45
+ description: "Charge for test@example.com"
46
+ )
47
+ ```
48
+
49
+ The PandaPay API takes this charge, relays it to Stripe on your behalf using the OAuth token obtained via Stripe Connect, less the donation amount (which will show up in Stripe as a "Panda Fee"). This also works with the standard Stripe **customer** parameter instead of a **source**.
50
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pandapay"
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
@@ -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,12 @@
1
+ require "pandapay/version"
2
+ require "pandapay/stripe_ecommerce"
3
+
4
+ module PandaPay
5
+ def self.api_key=(new_api_key)
6
+ @api_key = new_api_key
7
+ end
8
+
9
+ def self.api_key
10
+ @api_key
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ require 'restclient/exceptions'
2
+ require 'json'
3
+
4
+ module PandaPay
5
+ class Error < RuntimeError
6
+ def self.raise_from_restclient_error!(exception)
7
+ if exception.http_code == 400
8
+ raise PandaPay::RequestError.new JSON.parse(exception.http_body)
9
+ else
10
+ raise exception
11
+ end
12
+ end
13
+ end
14
+
15
+ class AuthenticationError < PandaPay::Error
16
+ DEFAULT_MESSAGE = "No API key provided. Set your API key using \"PandaPay.api_key = <API-KEY>\". You can generate API keys from the PandaPay web interface. See https://www.pandapay.io/docs/api-reference for details, or email support@pandpay.io if you have any questions."
17
+
18
+ def initialize(message=DEFAULT_MESSAGE)
19
+ super
20
+ end
21
+
22
+ def self.api_key_not_set!
23
+ raise self.new
24
+ end
25
+ end
26
+
27
+ class RequestError < PandaPay::Error
28
+ attr_reader :error_details
29
+
30
+ def initialize(error_details={})
31
+ @error_details = error_details
32
+
33
+ super self.error_details.inspect
34
+ end
35
+ end
36
+ end
37
+
@@ -0,0 +1,7 @@
1
+ require 'pandapay/stripe_ecommerce/charge'
2
+
3
+ module PandaPay
4
+ module StripeEcommerce
5
+ end
6
+ end
7
+
@@ -0,0 +1,79 @@
1
+ require 'restclient'
2
+ require 'pandapay/util'
3
+ require 'pandapay/errors'
4
+ require 'stripe'
5
+
6
+ module PandaPay
7
+ module StripeEcommerce
8
+ class Charge
9
+ extend PandaPay::Util
10
+
11
+ attr_reader :stripe_charge
12
+
13
+ def self.create(params={}, opts={})
14
+ opts = symbolize_keys opts
15
+ params = symbolize_keys params
16
+
17
+ api_key = opts.fetch :api_key, PandaPay.api_key
18
+
19
+ unless present? api_key
20
+ PandaPay::AuthenticationError.api_key_not_set!
21
+ end
22
+
23
+ params_to_use = {}
24
+ stripe_params = params.dup
25
+
26
+ params_to_use[:donation_amount] = stripe_params.delete :donation_amount
27
+ params_to_use[:destination] = stripe_params.delete :destination_ein
28
+ params_to_use[:receipt_email] = stripe_params.delete :receipt_email
29
+ params_to_use[:currency] = stripe_params.delete :currency
30
+
31
+ stripe_params.each do |attr, value|
32
+ params_to_use["stripe_params[#{attr}]"] = value
33
+ end
34
+
35
+ headers = {
36
+ accept: :json,
37
+ content_type: :json,
38
+ params: params_to_use
39
+ }.merge opts
40
+
41
+ api_key = headers.delete(:api_key) || PandaPay.api_key
42
+ api_base = headers.delete(:api_base) || "https://api.pandapay.io/v1"
43
+
44
+ begin
45
+ response = RestClient::Request.new(
46
+ method: :post,
47
+ url: File.join(api_base, "/donations"),
48
+ user: api_key,
49
+ password: nil,
50
+ headers: headers
51
+ ).execute
52
+ rescue RestClient::Exception => e
53
+ PandaPay::Error.raise_from_restclient_error! e
54
+ end
55
+
56
+ self.new JSON.parse(response), opts
57
+ end
58
+
59
+ protected
60
+
61
+ def initialize(response, opts)
62
+ response.each do |attr, value|
63
+ if attr == 'stripe_response'
64
+ @stripe_charge = Stripe::Util.convert_to_stripe_object(
65
+ response,
66
+ opts
67
+ )
68
+ else
69
+ unless self.respond_to?("#{attr}=")
70
+ self.class.send :attr_accessor, attr
71
+ end
72
+
73
+ self.send "#{attr}=", value
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,21 @@
1
+ module PandaPay
2
+ module Util
3
+ def present?(obj)
4
+ return false if obj.nil?
5
+
6
+ return false if obj.respond_to?(:length) && (obj.length == 0)
7
+
8
+ true
9
+ end
10
+
11
+ def symbolize_keys(hash)
12
+ new_hash = {}
13
+
14
+ hash.each do |k, v|
15
+ new_hash[k.to_sym] = v
16
+ end
17
+
18
+ new_hash
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module PandaPay
2
+ VERSION = "0.0.0.dev0"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pandapay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pandapay"
8
+ spec.version = PandaPay::VERSION
9
+ spec.authors = ["Dave Benvenuti"]
10
+ spec.email = ["dave@pandapay.io"]
11
+
12
+ spec.summary = "PandaPay Ruby Bindings"
13
+ spec.homepage = "https://github.com/ViralPhilanthropyInc/panda-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "stripe", "~> 1.43.0"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ spec.add_development_dependency "byebug"
27
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pandapay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0.dev0
5
+ platform: ruby
6
+ authors:
7
+ - Dave Benvenuti
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stripe
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.43.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.43.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - dave@pandapay.io
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".byebug_history"
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - lib/pandapay.rb
100
+ - lib/pandapay/errors.rb
101
+ - lib/pandapay/stripe_ecommerce.rb
102
+ - lib/pandapay/stripe_ecommerce/charge.rb
103
+ - lib/pandapay/util.rb
104
+ - lib/pandapay/version.rb
105
+ - pandapay.gemspec
106
+ homepage: https://github.com/ViralPhilanthropyInc/panda-ruby
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
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: 1.3.1
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: PandaPay Ruby Bindings
130
+ test_files: []