Skip to content

Commit

Permalink
added more bang
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanmartin committed May 20, 2012
1 parent c86f4b2 commit 9105d81
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
17 changes: 13 additions & 4 deletions README.markdown
Expand Up @@ -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
Expand All @@ -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'
```

Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.1.0
0.1.1
2 changes: 1 addition & 1 deletion lib/micropayment-rails/classes/base.rb
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions lib/micropayment-rails/classes/customer.rb
Expand Up @@ -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)
Expand All @@ -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 )
Expand Down
4 changes: 2 additions & 2 deletions lib/micropayment-rails/classes/session.rb
Expand Up @@ -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 )
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions micropayment-rails.gemspec
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9105d81

Please sign in to comment.