webpay-scaffold 0.0.1

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: cad6ee25e8423167f3196f0300279fec23e5f383
4
+ data.tar.gz: 3fa8bb5e775cfabd21db6cef3ba17a70d22bd1ac
5
+ SHA512:
6
+ metadata.gz: 0f90b0b663d8fd54013ccf1558b5c6e950072a7d3ae413608fae767b8d21127cd4378d166564e42411863583f808f9bdbd604579bc357cb1bc08a18f3a0adfd4
7
+ data.tar.gz: e9d415a6e6971a3f694f2b428eb391710f06358c63730349e5b9827fc9274cf3b83376c22272dea23bb3068dfd2072c58cf8928739fe423f1a865008a8027b6b
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webpay-scaffold.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 shu0115
2
+
3
+ MIT License
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,29 @@
1
+ # Webpay::Scaffold
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'webpay-scaffold'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install webpay-scaffold
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,34 @@
1
+ require "webpay/scaffold/version"
2
+ require 'rails/generators'
3
+ require 'webpay'
4
+ require 'rails_config'
5
+
6
+ module Webpay
7
+ class ScaffoldGenerator < Rails::Generators::Base
8
+ @@template_path = source_root File.expand_path( "../scaffold/templates", __FILE__ )
9
+
10
+ def generate_scaffold
11
+ ## config/initializers
12
+ copy_file( "#{@@template_path}/initializers/web_pay.rb", "config/initializers/web_pay.rb" )
13
+
14
+ ## db/migrate
15
+ copy_file( "#{@@template_path}/migrate/create_payments.rb", "db/migrate/20010101000000_create_payments.rb" )
16
+ copy_file( "#{@@template_path}/migrate/create_cards.rb", "db/migrate/20010102000000_create_cards.rb" )
17
+
18
+ ## models
19
+ copy_file( "#{@@template_path}/models/card.rb", "app/models/card.rb" )
20
+ copy_file( "#{@@template_path}/models/payment.rb", "app/models/payment.rb" )
21
+ copy_file( "#{@@template_path}/models/web_pay_connect.rb", "app/models/web_pay_connect.rb" )
22
+
23
+ ## settings
24
+ if File.exist?("config/settings.yml")
25
+ content = "\n# WebPay API Key\n"
26
+ content += "web_pay_api_key: 'test_secret_5ete0yfRC3g67ndfMm0kC1S9'\n"
27
+ content += "web_pay_currency: 'jpy'\n"
28
+ append_file( "config/settings.yml", content.force_encoding('ASCII-8BIT') )
29
+ else
30
+ copy_file( "#{@@template_path}/config/settings.yml", "config/settings.yml" )
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ # WebPay API Key
2
+ web_pay_api_key: 'test_secret_5ete0yfRC3g67ndfMm0kC1S9'
3
+ web_pay_currency: 'jpy'
@@ -0,0 +1 @@
1
+ WebPay.api_key = Settings.web_pay_api_key
@@ -0,0 +1,18 @@
1
+ class CreateCards < ActiveRecord::Migration
2
+ def change
3
+ create_table :cards do |t|
4
+ t.references :user, index: true
5
+ t.string :object
6
+ t.integer :exp_year
7
+ t.integer :exp_month
8
+ t.string :fingerprint
9
+ t.string :name
10
+ t.string :country
11
+ t.string :kind
12
+ t.string :cvc_check
13
+ t.string :last_four_number
14
+
15
+ t.timestamps
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,23 @@
1
+ class CreatePayments < ActiveRecord::Migration
2
+ def change
3
+ create_table :payments do |t|
4
+ t.references :user, index: true
5
+ t.string :provider
6
+ t.string :transaction_id
7
+ t.string :object
8
+ t.boolean :livemode
9
+ t.string :currency
10
+ t.string :description
11
+ t.integer :amount
12
+ t.integer :amount_refunded
13
+ t.string :customer
14
+ t.timestamp :created
15
+ t.boolean :paid
16
+ t.boolean :refunded
17
+ t.text :failure_message
18
+ t.boolean :captured
19
+
20
+ t.timestamps
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,3 @@
1
+ class Card < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,3 @@
1
+ class Payment < ActiveRecord::Base
2
+ belongs_to :user
3
+ end
@@ -0,0 +1,47 @@
1
+ module WebPayConnect
2
+ # 新しい課金の作成
3
+ def self.charge_create(amount, card, description)
4
+ WebPay.api_key = Settings.web_pay_api_key
5
+ response = WebPay::Charge.create(
6
+ amount: amount,
7
+ currency: Settings.web_pay_currency,
8
+ card: {
9
+ number: card[:number],
10
+ exp_month: card[:exp_month],
11
+ exp_year: card[:exp_year],
12
+ cvc: card[:cvc],
13
+ name: card[:name],
14
+ },
15
+ description: description
16
+ ).to_hash
17
+
18
+ card = response['card']
19
+ card['kind'] = card['type']
20
+ card['last_four_number'] = card['last4']
21
+ card.delete('type')
22
+ card.delete('last4')
23
+
24
+ response['provider'] = 'WebPay'
25
+ response['transaction_id'] = response['id']
26
+ response['created'] = Time.at(response['created']) rescue nil
27
+ response.delete('id')
28
+ response.delete('card')
29
+
30
+ return response, card
31
+ end
32
+
33
+ # 課金情報の取得
34
+ def self.charge_retrieve(transaction_id)
35
+ WebPay.api_key = Settings.web_pay_api_key
36
+ response = WebPay::Charge.retrieve(transaction_id).to_hash
37
+
38
+ return response
39
+ rescue => e
40
+ return e.message
41
+ end
42
+
43
+ # 課金リストの取得
44
+ def self.charge_list(count=10, offset=0, created=nil, customer=nil)
45
+ WebPay::Charge.all(count: count, offset: offset, created: created, customer: customer).map{ |x| x.to_hash }
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Webpay
2
+ module Scaffold
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webpay/scaffold/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "webpay-scaffold"
8
+ spec.version = Webpay::Scaffold::VERSION
9
+ spec.authors = ["shu0115"]
10
+ spec.email = ["s.matsumoto0115@gmail.com"]
11
+ spec.description = %q{Scaffold for WebPay.}
12
+ spec.summary = %q{WebPay Scaffold}
13
+ spec.homepage = "https://github.com/shu0115/webpay-scaffold"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "webpay"
25
+ spec.add_dependency "rails_config"
26
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpay-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shu0115
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webpay
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rails_config
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Scaffold for WebPay.
70
+ email:
71
+ - s.matsumoto0115@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - lib/webpay/scaffold.rb
82
+ - lib/webpay/scaffold/templates/config/settings.yml
83
+ - lib/webpay/scaffold/templates/initializers/web_pay.rb
84
+ - lib/webpay/scaffold/templates/migrate/create_cards.rb
85
+ - lib/webpay/scaffold/templates/migrate/create_payments.rb
86
+ - lib/webpay/scaffold/templates/models/card.rb
87
+ - lib/webpay/scaffold/templates/models/payment.rb
88
+ - lib/webpay/scaffold/templates/models/web_pay_connect.rb
89
+ - lib/webpay/scaffold/version.rb
90
+ - webpay-scaffold.gemspec
91
+ homepage: https://github.com/shu0115/webpay-scaffold
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.0.3
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: WebPay Scaffold
115
+ test_files: []