spreedly-core-ruby 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -209,7 +209,7 @@ For this example, I will be using an Authorize.net account that only has a login
209
209
 
210
210
  puts "Authorize.net gateway token is #{gateway.token}"
211
211
 
212
- For most users, you will start off using only one gateway token, and as such can configure it as an environment variable to hold your gateway token. In addition to the previous environment variables, the SpreedlyCore.configure method will also look for a SPREEDLYCORE_GATEWAY_TOKEN environment value.
212
+ For most users, you will start off using only one gateway token, and as such can configure it as an environment variable to hold your gateway token. In addition to the previous environment variables, the `SpreedlyCore.configure` method will also look for a SPREEDLYCORE_GATEWAY_TOKEN environment value.
213
213
 
214
214
  # create an initializer at config/initializers/spreedly_core.rb
215
215
  # values already set for ENV['SPREEDLYCORE_API_LOGIN'], ENV['SPREEDLYCORE_API_SECRET'], and ENV['SPREEDLYCORE_GATEWAY_TOKEN']
@@ -237,23 +237,35 @@ For those using multiple gateway tokens, there is a class variable that holds th
237
237
 
238
238
  Creating Payment Types Programatically
239
239
  ------------
240
- For those using multiple gateway tokens, there is a class variable that holds the active gateway token. Before running any sort of transaction against a payment method, you'll need to set the gateway token that you wish to charge against.
240
+ **Please note that this practice requires you to be PCI compliant!**
241
241
 
242
- SpreedlyCore.configure
243
-
244
- SpreedlyCore.gateway_token(paypal_gateway_token)
245
- SpreedlyCore::PaymentMethod.find(pm_token).purchase(550)
246
-
247
- SpreedlyCore.gateway_token(authorize_gateway_token)
248
- SpreedlyCore::PaymentMethod.find(pm_token).purchase(2885)
249
-
250
- SpreedlyCore.gateway_token(braintree_gateway_token)
251
- SpreedlyCore::PaymentMethod.find(pm_token).credit(150)
242
+ In special cases, you may want to create payment types programmatically and will not be using the transparent redirect functionality. This can be done using the `SpreedlyCore::PaymentMethod.create` method, and will behave as follows:
243
+
244
+ * Card validation is done in realtime, and a 422 Unprocessable will be returned if validation fails.
245
+ * Successful execution will return an AddPaymentMethodTransaction object (*not* a PaymentMethod object). Adding a payment method is wrapped in a transaction much like doing a purchase or authorize request is. The returned object will have the PaymentMethod object as a child.
246
+ * You still need to manually call `retain` on the payment method if you wish to retain the card.
247
+
248
+ The example below illustrates both a successful payment method creation, and how to handle one with errors.
249
+
250
+ SpreedlyCore.configure
251
+
252
+ pm_transaction = SpreedlyCore::PaymentMethod.create(:credit_card => good_card_hash)
253
+ pm_token = pm_transaction.payment_method.token
254
+ puts "Payment method token is #{pm_token}"
255
+
256
+ retain_transaction = pm_transaction.payment_method.retain
257
+ retain_transaction.succeeded? # true
258
+
259
+ begin
260
+ pm_transaction = SpreedlyCore::PaymentMethod.create(:credit_card => bad_card_hash)
261
+ rescue Exception => e
262
+ puts "Errors when submitting the card: #{e.errors.join(",")}"
263
+ end
252
264
 
253
265
  Contributing
254
266
  ------------
255
267
  1. [Fork](http://help.github.com/forking/) spreedly-core-ruby
256
- 2. Create a topic branch - `git checkout -b my_branch
268
+ 2. Create a topic branch - `git checkout -b my_branch`
257
269
  3. Make your changes on your topic branch.
258
270
  4. DO NOT bump the version number, or put it in a separate commit that I can ignore.
259
271
  3. Push to your branch - `git push origin my_branch`
@@ -32,8 +32,12 @@ module SpreedlyCore
32
32
  end
33
33
 
34
34
  class UnprocessableRequest < Error
35
+ attr_accessor :errors
36
+
35
37
  def initialize(errors)
36
38
  errors = [errors] unless errors.is_a?(Array)
39
+ @errors = errors
40
+
37
41
  super(errors.join("\n"))
38
42
  end
39
43
  end
@@ -1,4 +1,4 @@
1
1
  module SpreedlyCore
2
- Version = VERSION = "0.1.4"
2
+ Version = VERSION = "0.1.5"
3
3
  ApiVersion = API_VERSION = "v1"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreedly-core-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ date: 2012-03-21 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: httparty
17
- requirement: &70226775420580 !ruby/object:Gem::Requirement
17
+ requirement: &70270991883080 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - =
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.7.7
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70226775420580
25
+ version_requirements: *70270991883080
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &70226775420040 !ruby/object:Gem::Requirement
28
+ requirement: &70270991882520 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: 3.0.0
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70226775420040
36
+ version_requirements: *70270991882520
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: builder
39
- requirement: &70226775419660 !ruby/object:Gem::Requirement
39
+ requirement: &70270991882080 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70226775419660
47
+ version_requirements: *70270991882080
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: ruby-debug19
50
- requirement: &70226775419000 !ruby/object:Gem::Requirement
50
+ requirement: &70270991881440 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70226775419000
58
+ version_requirements: *70270991881440
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rake
61
- requirement: &70226775418400 !ruby/object:Gem::Requirement
61
+ requirement: &70270991880840 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - =
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 0.8.7
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70226775418400
69
+ version_requirements: *70270991880840
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: webmock
72
- requirement: &70226775417800 !ruby/object:Gem::Requirement
72
+ requirement: &70270991880280 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: 1.6.2
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70226775417800
80
+ version_requirements: *70270991880280
81
81
  description: Spreedly Core is a cloud service that allows you to store credit cards
82
82
  and run transactions against them, enabling you to accept payments on your website
83
83
  while avoiding all liability and PCI compliance requirements.