Skip to content
Browse files

added more bang

  • Loading branch information...
1 parent c86f4b2 commit 9105d8113601212b67898e2a4b9fe3e24b99f765 @jeanmartin jeanmartin committed May 20, 2012
View
17 README.markdown
@@ -11,15 +11,24 @@ gem 'micropayment-rails'
## Usage
+In an initializer (e.g. config/initializers/micropayment.rb):
+```
+Micropayment.setup do |config|
+ config.api_key = 'your api key from micropayment.de'
+ config.sandbox = 1 # to enable sandbox mode
+end
+```
+
+Let's play with the API:
```
# create a blank customer
-customer = Micropayment::Customer.create
+customer = Micropayment::Customer.create!
# create a customer with a customer id
-customer = Micropayment::Customer.create :customerId => 'my_customer_id'
+customer = Micropayment::Customer.create! :customerId => 'my_customer_id'
# create a customer with a bank_account
-customer = Micropayment::Customer.create :bank_account => { :bankCode => '10010010', :accountNumber => '1234567', :accountHolder => 'Jeff Winger' }
+customer = Micropayment::Customer.create! :bank_account => { :bankCode => '10010010', :accountNumber => '1234567', :accountHolder => 'Jeff Winger' }
# access a customers bank account
customer.bank_account
@@ -29,7 +38,7 @@ customer.bank_account = { :bankCode => '10010010', :accountNumber => '1234567',
# initiate a session
# (defaults for all hash params can be set on micropayment.de)
-Micropayment::Session.create 'project_key', customer, :amount => 1000, :currency => 'EUR'
+Micropayment::Session.create! 'project_key', customer, :amount => 1000, :currency => 'EUR'
```
View
2 VERSION
@@ -1 +1 @@
-0.1.0
+0.1.1
View
2 lib/micropayment-rails/classes/base.rb
@@ -23,7 +23,7 @@ def self.find(id)
end
end
- def self.create(id, params={})
+ def self.create!(id, params={})
params.symbolized_keys!
params.merge!(self::IDENTIFIER => id) if id
result = Micropayment::Debit.send self::CREATE_METHOD, params
View
10 lib/micropayment-rails/classes/customer.rb
@@ -28,11 +28,11 @@ def self.find(customerId)
when "0"
self.new( :customerId => customerId, :freeParams => result["freeParams"] )
else
- raise "#{result["error"]}: #{result["errorMessage"]}"
+ raise "Customer#find - #{result["error"]}: #{result["errorMessage"]}"
end
end
- def self.create(params={})
+ def self.create!(params={})
params.symbolized_keys!
bank_account_params = params.delete(:bank_account)
address_params = params.delete(:address)
@@ -51,6 +51,12 @@ def self.create(params={})
end
end
+ def self.find_or_create_by_id(id, params={})
+ params.symbolized_keys!
+ obj = (find(id) rescue nil)
+ obj ? obj : create( params.merge(:customerId => id) )
+ end
+
def self.session_list
# TODO wrap in an array
Micropayment::Debit.sessionList( :customerId => id )
View
4 lib/micropayment-rails/classes/session.rb
@@ -7,7 +7,7 @@ class Session < Micropayment::Base
CREATE_METHOD = :sessionCreate
- def create(project, customer, params={})
+ def create!(project, customer, params={})
params.symbolize_keys!
params.merge!( :customerId => customer.id, :project => project )
result = Micropayment::Debit.sessionCreate( params )
@@ -19,7 +19,7 @@ def create(project, customer, params={})
end
end
- def approve
+ def approve!
result = Micropayment::Debit.sessionApprove( :sessionId => id )
case result["error"]
when "0"
View
4 micropayment-rails.gemspec
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Jan Schwenzien"]
- s.date = "2012-05-19"
+ s.date = "2012-05-20"
s.description = "Use the micropayment API in your Rails project."
s.email = "jan@general-scripting.com"
s.extra_rdoc_files = [
@@ -38,7 +38,7 @@ Gem::Specification.new do |s|
s.homepage = "http://github.com/jeanmartin/micropayment-rails"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
- s.rubygems_version = "1.8.23"
+ s.rubygems_version = "1.8.22"
s.summary = "Rails wrapper for the micropayment gem"
if s.respond_to? :specification_version then

0 comments on commit 9105d81

Please sign in to comment.
Something went wrong with that request. Please try again.