paypal-scaffold 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.8.0"
10
+ gem "rdoc", "~> 3.12"
11
+ # gem "bundler", "~> 1.0.0"
12
+ gem "jeweler", "~> 1.8.3"
13
+ # gem "rcov", ">= 0"
14
+ end
15
+
16
+ gem 'paypal-express'
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 shu_0115
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = paypal-scaffold
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to paypal-scaffold
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 shu_0115. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "paypal-scaffold"
18
+ gem.homepage = "http://github.com/shu0115/paypal-scaffold"
19
+ gem.license = "MIT"
20
+ gem.summary = "PayPal Scaffold"
21
+ gem.description = "Scaffold for PayPal."
22
+ gem.email = "raisondetre0115@gmail.com"
23
+ gem.authors = ["shu_0115"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "paypal-scaffold #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ require 'rails/generators'
3
+
4
+ module Paypal
5
+ module Generators
6
+ class ScaffoldGenerator < ::Rails::Generators::Base
7
+
8
+ source_root File.expand_path("../templates", __FILE__)
9
+ desc "This generator scaffold for PayPal"
10
+
11
+ def generate_scaffold
12
+ # App
13
+ copy_file "app/models/paypal_api.rb", "app/models/paypal_api.rb"
14
+
15
+ # Config
16
+ if File.exist?('config/initializers/local_setting.rb')
17
+ content = "\n# PayPal\n"
18
+ content += "ENV['PAYPAL_SANDBOX'] = \"ON\"\n"
19
+ content += "ENV['PAYPAL_USER_NAME'] = \"test01_1336296393_biz_api1.gmail.com\"\n"
20
+ content += "ENV['PAYPAL_PASSWORD'] = \"1336296414\"\n"
21
+ content += "ENV['PAYPAL_SIGNATURE'] = \"AiPC9BjkCyDFQXbSkoZcgqH3hpacAzpTbNTAkYEP8T8QC6kv0aF-gRj-\"\n"
22
+ content += "ENV['PAYPAL_PERIOD'] = \"Month\" # 周期 ie.) :Month, :Week, :Day\n"
23
+ content += "ENV['PAYPAL_FREQUENCY'] = \"1\" # 回数\n"
24
+ content += "ENV['PAYPAL_AMOUNT'] = \"150\" # 金額\n"
25
+
26
+ append_file "config/initializers/local_setting.rb", content.force_encoding('ASCII-8BIT')
27
+ else
28
+ copy_file "config/initializers/local_setting.rb", "config/initializers/local_setting.rb"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,112 @@
1
+ # coding: utf-8
2
+ class PaypalApi
3
+
4
+ private
5
+
6
+ # PayPal Setting
7
+ Paypal.sandbox = ENV['PAYPAL_SANDBOX'] == "ON" ? true : false
8
+ PAYPAL_USER_NAME = ENV['PAYPAL_USER_NAME']
9
+ PAYPAL_PASSWORD = ENV['PAYPAL_PASSWORD']
10
+ PAYPAL_SIGNATURE = ENV['PAYPAL_SIGNATURE']
11
+ PAYPAL_PERIOD = ENV['PAYPAL_PERIOD'].to_sym # 周期
12
+ PAYPAL_FREQUENCY = ENV['PAYPAL_FREQUENCY'].to_i # 回数
13
+ PAYPAL_AMOUNT = ENV['PAYPAL_AMOUNT'].to_i # 金額
14
+
15
+ #------------------#
16
+ # self.get_request #
17
+ #------------------#
18
+ # リクエスト生成
19
+ def self.get_request
20
+ request = Paypal::Express::Request.new(
21
+ username: PAYPAL_USER_NAME,
22
+ password: PAYPAL_PASSWORD,
23
+ signature: PAYPAL_SIGNATURE,
24
+ )
25
+
26
+ return request
27
+ end
28
+
29
+ #---------------------------#
30
+ # self.set_express_checkout #
31
+ #---------------------------#
32
+ # チェックアウト開始
33
+ # IN : success_calback - 成功時のリダイレクト先URL
34
+ # : cancel_calback - キャンセル時のリダイレクト先URL
35
+ # : description - チェックアウトの説明(create_recurring - Paypal::Payment::Recurringのdescriptionに渡す値と同じでなければならない)
36
+ # OUT : response.redirect_uri - チェックアウト開始用PayPal側URL
37
+ # def self.set_express_checkout( success_calback_url, cancel_calback_url )
38
+ def self.set_express_checkout( args )
39
+ success_calback = args[:success_calback]
40
+ cancel_calback = args[:cancel_calback]
41
+ description = args[:description]
42
+
43
+ request = self.get_request
44
+
45
+ payment_request = Paypal::Payment::Request.new(
46
+ currency_code: :JPY, # if nil, PayPal use USD as default
47
+ billing_type: :RecurringPayments,
48
+ billing_agreement_description: description,
49
+ )
50
+
51
+ response = request.setup(
52
+ payment_request,
53
+ success_calback,
54
+ cancel_calback,
55
+ )
56
+
57
+ return response.redirect_uri
58
+ end
59
+
60
+ #-----------------------#
61
+ # self.create_recurring #
62
+ #-----------------------#
63
+ # プロフィール作成
64
+ # IN : token - PayPalからリダイレクトで帰って来た時のparams[:token]から取得
65
+ # OUT : response.recurring.identifier # => profile_id
66
+ def self.create_recurring( token, description )
67
+ request = self.get_request
68
+
69
+ profile = Paypal::Payment::Recurring.new(
70
+ start_date: Time.now,
71
+ description: description,
72
+ billing: {
73
+ period: PAYPAL_PERIOD,
74
+ frequency: PAYPAL_FREQUENCY,
75
+ amount: PAYPAL_AMOUNT,
76
+ currency_code: :JPY, # if nil, PayPal use USD as default
77
+ }
78
+ )
79
+
80
+ response = request.subscribe!( token, profile )
81
+ response.recurring
82
+
83
+ return response.recurring.identifier # => profile_id
84
+ end
85
+
86
+ #----------------------------#
87
+ # self.get_recurring_profile #
88
+ #----------------------------#
89
+ # プロフィール取得
90
+ # IN : profile_id
91
+ # OUT : response.recurring
92
+ def self.get_recurring_profile( profile_id )
93
+ request = self.get_request
94
+ response = request.subscription(profile_id)
95
+
96
+ return response.recurring
97
+ end
98
+
99
+ #-----------------------#
100
+ # self.cancel_recurring #
101
+ #-----------------------#
102
+ # キャンセル
103
+ # IN : profile_id
104
+ # OUT : response.ack - "Success" OR Others
105
+ def self.cancel_recurring( profile_id )
106
+ request = self.get_request
107
+ response = request.renew!( profile_id, :Cancel )
108
+
109
+ return response.ack
110
+ end
111
+
112
+ end
@@ -0,0 +1,10 @@
1
+ # coding: utf-8
2
+
3
+ # PayPal
4
+ ENV['PAYPAL_SANDBOX'] = "ON"
5
+ ENV['PAYPAL_USER_NAME'] = "test01_1336296393_biz_api1.gmail.com"
6
+ ENV['PAYPAL_PASSWORD'] = "1336296414"
7
+ ENV['PAYPAL_SIGNATURE'] = "AiPC9BjkCyDFQXbSkoZcgqH3hpacAzpTbNTAkYEP8T8QC6kv0aF-gRj-"
8
+ ENV['PAYPAL_PERIOD'] = "Month" # 周期 ie.) :Month, :Week, :Day
9
+ ENV['PAYPAL_FREQUENCY'] = "1" # 回数
10
+ ENV['PAYPAL_AMOUNT'] = "150" # 金額
@@ -0,0 +1,61 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "paypal-scaffold"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["shu_0115"]
12
+ s.date = "2012-05-12"
13
+ s.description = "Scaffold for PayPal."
14
+ s.email = "raisondetre0115@gmail.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rspec",
22
+ "Gemfile",
23
+ "LICENSE.txt",
24
+ "README.rdoc",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/generators/paypal/scaffold/scaffold_generator.rb",
28
+ "lib/generators/paypal/scaffold/templates/app/models/paypal_api.rb",
29
+ "lib/generators/paypal/scaffold/templates/config/initializers/local_setting.rb",
30
+ "paypal-scaffold.gemspec",
31
+ "spec/paypal-scaffold_spec.rb",
32
+ "spec/spec_helper.rb"
33
+ ]
34
+ s.homepage = "http://github.com/shu0115/paypal-scaffold"
35
+ s.licenses = ["MIT"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = "1.8.23"
38
+ s.summary = "PayPal Scaffold"
39
+
40
+ if s.respond_to? :specification_version then
41
+ s.specification_version = 3
42
+
43
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
44
+ s.add_runtime_dependency(%q<paypal-express>, [">= 0"])
45
+ s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
46
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
47
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
48
+ else
49
+ s.add_dependency(%q<paypal-express>, [">= 0"])
50
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
51
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
52
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
53
+ end
54
+ else
55
+ s.add_dependency(%q<paypal-express>, [">= 0"])
56
+ s.add_dependency(%q<rspec>, ["~> 2.8.0"])
57
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
58
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
59
+ end
60
+ end
61
+
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "PaypalScaffold" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'paypal-scaffold'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paypal-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - shu_0115
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: paypal-express
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.8.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.8.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rdoc
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '3.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '3.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: jeweler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 1.8.3
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.3
78
+ description: Scaffold for PayPal.
79
+ email: raisondetre0115@gmail.com
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files:
83
+ - LICENSE.txt
84
+ - README.rdoc
85
+ files:
86
+ - .document
87
+ - .rspec
88
+ - Gemfile
89
+ - LICENSE.txt
90
+ - README.rdoc
91
+ - Rakefile
92
+ - VERSION
93
+ - lib/generators/paypal/scaffold/scaffold_generator.rb
94
+ - lib/generators/paypal/scaffold/templates/app/models/paypal_api.rb
95
+ - lib/generators/paypal/scaffold/templates/config/initializers/local_setting.rb
96
+ - paypal-scaffold.gemspec
97
+ - spec/paypal-scaffold_spec.rb
98
+ - spec/spec_helper.rb
99
+ homepage: http://github.com/shu0115/paypal-scaffold
100
+ licenses:
101
+ - MIT
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ segments:
113
+ - 0
114
+ hash: -1759516614426047787
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
117
+ requirements:
118
+ - - ! '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubyforge_project:
123
+ rubygems_version: 1.8.23
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: PayPal Scaffold
127
+ test_files: []