yukon 0.1.0

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: c9ed971776d4eefbe48dbf3f284e1829047f19be
4
+ data.tar.gz: ddd1756cec0ec7c8793decc8c6c77481cbcb9495
5
+ SHA512:
6
+ metadata.gz: ce7bb7734fb59a4ecd5cdef9657637ef1f5f09f789e634f06fb20968a024da61979625b96ff8774c189008682b456adc6774fc6253e39dc87cce367223307d18
7
+ data.tar.gz: 211134e2a96cc1a91da4f5c6613bbcf6803d00d1db811ab1679e0f7212263c71f853acac757b0ed1fcb7c69256398e32848f2be7c1d2decde41963cfa9168c26
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format doc
@@ -0,0 +1 @@
1
+ yukon
@@ -0,0 +1 @@
1
+ 2.2.2
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yukon.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Bala Paranj
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,85 @@
1
+ # Yukon
2
+
3
+ This Micro Gem encapsulates Express Checkout Paypal API. To experiment with that code, run `bin/console` for an interactive prompt. To play with cart object:
4
+
5
+ ```ruby
6
+ require_relative './lib/yukon/cart.rb'
7
+ ```
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'yukon'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install yukon
24
+
25
+ ## Usage
26
+
27
+ 1. SetExpressCheckout: Makes a call to the API sending the details of the payment to obtain a token and generate a payment url
28
+ 2. GetExpressCheckout: Redirects the user to the payment url and obtains the authorization
29
+ 3. DoExpressCheckout: Uses the given authorization to make the real payment
30
+
31
+ ## Test Credentials
32
+
33
+ Credentials Test
34
+
35
+ Once you’ve set up your test accounts and have your API test credentials, you’re ready to make PayPal requests to the Sandbox environment.
36
+
37
+ The following cURL command makes an Express Checkout call to the Sandbox. Execute the request from the command line by replacing the credential values in the command with those from your Sandbox Business account. You should get success in response to the request:
38
+
39
+ Request:
40
+ curl -s --insecure https://api-3t.sandbox.paypal.com/nvp -d "USER=bparan_1360459336_biz_api1.gmail.com&PWD=1360459362&SIGNATURE=AiPC9BjkCyDFQXbSkoZcgqH3hpacARbNPHYwGcAEv3pAorm.KuIxgJw8&METHOD=SetExpressCheckout&VERSION=98&PAYMENTREQUEST_0_AMT=10&PAYMENTREQUEST_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_PAYMENTACTION=SALE&cancelUrl=http://www.example.com/cancel.html&returnUrl=http://www.example.com/success.html"
41
+
42
+ Response:
43
+ TOKEN=EC%2d7E679406DY7307812&TIMESTAMP=2015%2d08%2d16T20%3a54%3a43Z&CORRELATIONID=61233e65728ce&ACK=Success&VERSION=98&BUILD=000000
44
+
45
+
46
+ Use the following sample by replacing <tokenValue> with the token from the SetExpressCheckoutPayment response:
47
+
48
+ curl -s --insecure https://api-3t.sandbox.paypal.com/nvp -d "USER=bparan_1360459336_biz_api1.gmail.com&PWD=1360459362&SIGNATURE=AiPC9BjkCyDFQXbSkoZcgqH3hpacARbNPHYwGcAEv3pAorm.KuIxgJw8&METHOD=GetExpressCheckoutDetails&VERSION=93&TOKEN=<tokenValue>"
49
+
50
+ The response from this call includes the PayerID value, which is needed to capture the payment:
51
+
52
+ GetExpressCheckoutDetails response:
53
+
54
+ TOKEN=EC%2d4RX1920730957200V
55
+ ...
56
+
57
+ &PAYERID=6B9DKHQRKW4SG
58
+ ...
59
+
60
+ Paypal Test Credentials
61
+
62
+ test:
63
+ username: jb-us-seller_api1.paypal.com
64
+ password: WX4WTU3S8MY44S7F
65
+ signature: AFcWxV21C7fd0v3bYYYRCpSSRl31A7yDhhsPUU2XhtMoZXsWHFxu-RWy
66
+ app_id: APP-80W284485P519543T
67
+ http_timeout: 30
68
+ mode: sandbox
69
+ sandbox_email_address: platform.sdk.seller@gmail.com
70
+
71
+ ## Development
72
+
73
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
74
+
75
+ 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).
76
+
77
+ ## Contributing
78
+
79
+ Bug reports and pull requests are welcome on GitHub at https://bitbucket.orb/bparanj/yukon.
80
+
81
+
82
+ ## License
83
+
84
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
85
+
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yukon"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,15 @@
1
+ require "yukon/version"
2
+ require 'helpers/configuration'
3
+
4
+ module Yukon
5
+ extend Configuration
6
+
7
+ # Paypal Credentials
8
+ define_setting :login
9
+ define_setting :password
10
+ define_setting :signature
11
+
12
+ # ActiveMerchant gateway mode
13
+ define_setting :mode, :test
14
+
15
+ end
@@ -0,0 +1,26 @@
1
+ module Yukon
2
+ class Cart
3
+
4
+ def initialize(product)
5
+ @product = product
6
+ end
7
+
8
+ def total_amount
9
+ contents[:items][0][:amount]
10
+ end
11
+
12
+ def contents
13
+ {
14
+ items: [
15
+ {
16
+ name: @product.name,
17
+ amount: @product.price_in_cents,
18
+ quantity: 1,
19
+ description: "Digital product purchase"
20
+ }
21
+ ]
22
+ }
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,3 @@
1
+ module Yukon
2
+ EndPoint = Struct.new(:return_url, :cancel_return_url, :notify_url)
3
+ end
@@ -0,0 +1,25 @@
1
+ module Yukon
2
+ # Value object
3
+ class ExpressCheckout
4
+ attr_reader :end_point, :cart, :buyer_ip, :custom
5
+
6
+ def initialize(end_point, cart, buyer_ip, custom)
7
+ @end_point = end_point
8
+ @cart = cart
9
+ @buyer_ip = buyer_ip
10
+ @custom = custom
11
+ end
12
+
13
+ def to_h
14
+ {
15
+ ip: @buyer_ip,
16
+ return_url: @end_point.return_url,
17
+ cancel_return_url: @end_point.cancel_return_url,
18
+ notify_url: @end_point.notify_url,
19
+ allow_guest_checkout: true,
20
+ custom: @custom
21
+ }.merge(@cart.contents)
22
+ end
23
+ end
24
+
25
+ end
@@ -0,0 +1,14 @@
1
+ module Yukon
2
+ class PaypalExpressGateway
3
+ def initialize(product, gateway)
4
+ @product = product
5
+ @gateway = gateway
6
+ end
7
+
8
+ def set_express_checkout(express_checkout)
9
+ cart = express_checkout.cart
10
+
11
+ @gateway.setup_purchase(cart.total_amount, express_checkout.to_h)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_merchant'
2
+
3
+ module Yukon
4
+ class PaypalExpressGatewayFactory
5
+ def self.instance(login, password, signature, seller_email)
6
+ options = {
7
+ login: login,
8
+ password: password,
9
+ signature: signature,
10
+ subject: seller_email
11
+ }
12
+
13
+ ActiveMerchant::Billing::PaypalExpressGateway.new(options)
14
+ end
15
+ end
16
+
17
+ end
18
+
@@ -0,0 +1,3 @@
1
+ module Yukon
2
+ VERSION = "0.1.0"
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 'yukon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yukon"
8
+ spec.version = Yukon::VERSION
9
+ spec.authors = ["Bala Paranj"]
10
+ spec.email = ["bparanj@gmail.com"]
11
+
12
+ spec.summary = %q{Payment processing using Paypal.}
13
+ spec.description = %q{Express checkout using ActiveMerchant Paypal API.}
14
+ spec.homepage = "http://www.rubyplus.com"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'activemerchant', "~> 1.52"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.3"
27
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yukon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bala Paranj
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemerchant
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.52'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.52'
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.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.3'
69
+ description: Express checkout using ActiveMerchant Paypal API.
70
+ email:
71
+ - bparanj@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/yukon.rb
88
+ - lib/yukon/cart.rb
89
+ - lib/yukon/end_point.rb
90
+ - lib/yukon/express_checkout.rb
91
+ - lib/yukon/paypal_express_gateway.rb
92
+ - lib/yukon/paypal_express_gateway_factory.rb
93
+ - lib/yukon/version.rb
94
+ - yukon.gemspec
95
+ homepage: http://www.rubyplus.com
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Payment processing using Paypal.
119
+ test_files: []