cardia 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cardia/credit_card_transaction.rb +10 -3
- data/lib/cardia/money.rb +17 -7
- data/lib/cardia/order.rb +3 -3
- data/lib/cardia/version.rb +1 -1
- data/test_integration/test_acceptance.rb +1 -2
- data/website/index.html +2 -2
- data/website/index.txt +1 -2
- metadata +2 -2
@@ -17,9 +17,14 @@ module Cardia
|
|
17
17
|
# transaction.merchant = merchant
|
18
18
|
#
|
19
19
|
# card = Cardia::CreditCard.valid_card_for_testing
|
20
|
-
#
|
20
|
+
#
|
21
|
+
# For regular transactions, use:
|
21
22
|
# status = transaction.register(card)
|
22
23
|
#
|
24
|
+
# For 3d secure, use:
|
25
|
+
# status = transaction.register_3d(card, "http://my.success.url/", "http://my.failure.url/")
|
26
|
+
# This will return a URL that the user should be redirected to. When the user is sent to this address he will either be redirected to
|
27
|
+
# either the success or failure URL, depending on whether the payment was successful.
|
23
28
|
class CreditCardTransaction
|
24
29
|
|
25
30
|
attr_reader :order, :verification_address
|
@@ -30,7 +35,8 @@ module Cardia
|
|
30
35
|
@http = http_connection
|
31
36
|
end
|
32
37
|
|
33
|
-
# Creates a new instance. Send along your Order as the parameter, see
|
38
|
+
# Creates a new instance. Send along your Order as the parameter, see Cardia::Order for methods that should be implemented in your order
|
39
|
+
# * _an_order_ The order
|
34
40
|
def self.with_http_connection(an_order)
|
35
41
|
http = Net::HTTP.new(self.server_name,"443")
|
36
42
|
http.use_ssl = true
|
@@ -38,6 +44,7 @@ module Cardia
|
|
38
44
|
end
|
39
45
|
|
40
46
|
# Send along the Cardia::Merchant that the payment is for
|
47
|
+
# * _a_merchant_ a Cardia::Merchant
|
41
48
|
def merchant=(a_merchant)
|
42
49
|
@merchant = a_merchant
|
43
50
|
end
|
@@ -122,7 +129,7 @@ module Cardia
|
|
122
129
|
return REXML::Document.new(response.body)
|
123
130
|
end
|
124
131
|
|
125
|
-
# Register using 3DSecure.
|
132
|
+
# Register using 3DSecure. Send along a card, a URL for redirection after successful payments and a URL to redirect to when the payment was unsuccessful.
|
126
133
|
def register_3d(a_credit_card, success_url, failure_url)
|
127
134
|
raise "No verification code supplied" if a_credit_card.verification_value.nil?
|
128
135
|
params = {
|
data/lib/cardia/money.rb
CHANGED
@@ -1,54 +1,64 @@
|
|
1
1
|
module Cardia
|
2
|
+
# A very basic Money class, at the time being works with Norwegian Kroner
|
2
3
|
class Money
|
3
4
|
attr_reader :amount
|
5
|
+
|
6
|
+
# Create an instance for NOK
|
4
7
|
def self.kroner(an_amount)
|
5
8
|
an_amount = an_amount.to_i
|
6
9
|
self.new(an_amount * 100)
|
7
10
|
end
|
8
|
-
|
11
|
+
|
12
|
+
def initialize(an_amount) #:nodoc:
|
9
13
|
@amount = an_amount
|
10
14
|
end
|
11
15
|
|
12
|
-
def times(factor_integer)
|
16
|
+
def times(factor_integer) #:nodoc:
|
13
17
|
self.class.new(factor_integer * @amount)
|
14
18
|
end
|
15
19
|
|
16
|
-
def plus(a_money)
|
20
|
+
def plus(a_money) #:nodoc:
|
17
21
|
self.class.new(a_money. amount + @amount)
|
18
22
|
end
|
19
23
|
|
20
|
-
def +(a_money)
|
24
|
+
def +(a_money) #:nodoc:
|
21
25
|
self.plus(a_money)
|
22
26
|
end
|
23
27
|
|
28
|
+
# Return the object as Norwegian Kroner
|
24
29
|
def kroner
|
25
30
|
(@amount / 100).truncate
|
26
31
|
end
|
27
32
|
|
33
|
+
# Return the øre
|
28
34
|
def oere
|
29
35
|
@amount - kroner * 100
|
30
36
|
end
|
31
37
|
|
32
|
-
def nil?
|
38
|
+
def nil? #:nodoc:
|
33
39
|
@amount.nil?
|
34
40
|
end
|
35
41
|
|
42
|
+
# Return a new instance including tax
|
36
43
|
def including_tax(tax_percentage)
|
37
44
|
self.class.new((self.amount + self.amount * (tax_percentage / 100.0)).round)
|
38
45
|
end
|
39
46
|
|
47
|
+
# Equality test, returns true for two objects of the same amount
|
40
48
|
def ==(an_object)
|
41
49
|
self.class == an_object.class and self.amount == an_object.amount
|
42
50
|
end
|
43
51
|
|
52
|
+
# String representation
|
44
53
|
def to_s
|
45
54
|
"#{self.to_i},-"
|
46
55
|
end
|
47
56
|
|
48
|
-
def to_i
|
57
|
+
def to_i #:nodoc:
|
49
58
|
(@amount/100.0).round
|
50
59
|
end
|
51
|
-
|
60
|
+
|
61
|
+
# Formatted print
|
52
62
|
def format_kroner_dot_oere
|
53
63
|
return "%d.%.2d" % [self.kroner, self.oere]
|
54
64
|
end
|
data/lib/cardia/order.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
module Cardia
|
2
|
-
# This is the very minimum that's required in order for
|
2
|
+
# This is the very minimum that's required in order for an Order to function. You probably have your own...
|
3
3
|
# For home baked order classes, you need to implement methods listed below
|
4
4
|
class Order
|
5
5
|
attr_reader :amount, :description, :reference
|
6
6
|
attr_accessor :customer, :status
|
7
7
|
|
8
8
|
# Creates an instance: Parameters:
|
9
|
-
# * +
|
10
|
-
# * +
|
9
|
+
# * +_amount_+: The amount as an integer
|
10
|
+
# * +_description_+: Give a describing name (not used for much...)
|
11
11
|
def initialize(amount, description)
|
12
12
|
@amount,@description = amount, description
|
13
13
|
@reference = rand(10000)
|
data/lib/cardia/version.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class CardiaAcceptanceTest < Test::Unit::TestCase
|
2
2
|
def visa_card_for_testing
|
3
3
|
result = Cardia::CreditCard.new
|
4
|
-
result.number = "
|
4
|
+
result.number = "4444333322221111"
|
5
5
|
result.verification_value = "081"
|
6
6
|
result.expiry_date = Date.parse("2009-03-01")
|
7
7
|
result.type = "visa"
|
@@ -22,7 +22,6 @@ class CardiaAcceptanceTest < Test::Unit::TestCase
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def real_merchant
|
25
|
-
# Cardia::Merchant.with_token("0f0c518f-dc4f-4219-a356-9cbec52273d9")
|
26
25
|
Cardia::Merchant.test_merchant
|
27
26
|
end
|
28
27
|
|
data/website/index.html
CHANGED
@@ -65,7 +65,7 @@
|
|
65
65
|
<h2>Forum</h2>
|
66
66
|
|
67
67
|
|
68
|
-
<p><a href="http://
|
68
|
+
<p><a href="http://groups.google.com/group/cardia4ruby">We have a Google Group for this code</a></p>
|
69
69
|
|
70
70
|
|
71
71
|
<h2>This is a work in progress</h2>
|
@@ -73,7 +73,7 @@
|
|
73
73
|
|
74
74
|
<p>Although this is extracted from production quality code, this is a work in progress.</p>
|
75
75
|
<p class="coda">
|
76
|
-
<a href="">TODO</a>,
|
76
|
+
<a href="">TODO</a>, 3rd September 2007<br>
|
77
77
|
Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
|
78
78
|
</p>
|
79
79
|
</div>
|
data/website/index.txt
CHANGED
@@ -21,8 +21,7 @@ h2. Demonstration of usage
|
|
21
21
|
|
22
22
|
h2. Forum
|
23
23
|
|
24
|
-
|
25
|
-
"http://rubyforge.org/forum/?group_id=4344":http://rubyforge.org/forum/?group_id=4344
|
24
|
+
"We have a Google Group for this code":http://groups.google.com/group/cardia4ruby
|
26
25
|
|
27
26
|
h2. This is a work in progress
|
28
27
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: cardia
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.0.
|
7
|
-
date: 2007-09-
|
6
|
+
version: 0.0.3
|
7
|
+
date: 2007-09-04 00:00:00 +02:00
|
8
8
|
summary: provides credit card payments through Cardia
|
9
9
|
require_paths:
|
10
10
|
- lib
|