braintree 2.5.2 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/braintree.rb +1 -0
- data/lib/braintree/address.rb +3 -3
- data/lib/braintree/address/country_names.rb +251 -0
- data/lib/braintree/customer.rb +4 -4
- data/lib/braintree/error_codes.rb +1 -0
- data/lib/braintree/error_result.rb +2 -1
- data/lib/braintree/subscription.rb +8 -1
- data/lib/braintree/subscription_gateway.rb +6 -2
- data/lib/braintree/transaction.rb +11 -6
- data/lib/braintree/version.rb +2 -2
- data/spec/integration/braintree/subscription_spec.rb +72 -33
- data/spec/integration/braintree/transaction_search_spec.rb +8 -0
- data/spec/integration/braintree/transaction_spec.rb +6 -13
- metadata +5 -4
data/lib/braintree.rb
CHANGED
data/lib/braintree/address.rb
CHANGED
@@ -43,13 +43,13 @@ module Braintree
|
|
43
43
|
|
44
44
|
# Deprecated. Use Braintree::Address.delete
|
45
45
|
def delete
|
46
|
-
warn "[DEPRECATED] delete as an instance method is deprecated. Please use
|
46
|
+
warn "[DEPRECATED] delete as an instance method is deprecated. Please use Address.delete"
|
47
47
|
@gateway.address.delete(customer_id, self.id)
|
48
48
|
end
|
49
49
|
|
50
50
|
# Deprecated. Use Braintree::Address.update
|
51
51
|
def update(attributes)
|
52
|
-
warn "[DEPRECATED] update as an instance method is deprecated. Please use
|
52
|
+
warn "[DEPRECATED] update as an instance method is deprecated. Please use Address.update"
|
53
53
|
result = @gateway.address.update(customer_id, id, attributes)
|
54
54
|
if result.success?
|
55
55
|
copy_instance_variables_from_object result.address
|
@@ -59,7 +59,7 @@ module Braintree
|
|
59
59
|
|
60
60
|
# Deprecated. Use Braintree::Address.update!
|
61
61
|
def update!(attributes)
|
62
|
-
warn "[DEPRECATED] update! as an instance method is deprecated. Please use
|
62
|
+
warn "[DEPRECATED] update! as an instance method is deprecated. Please use Address.update!"
|
63
63
|
return_object_or_raise(:address) { update(attributes) }
|
64
64
|
end
|
65
65
|
|
@@ -0,0 +1,251 @@
|
|
1
|
+
module Braintree
|
2
|
+
class Address
|
3
|
+
CountryNames = [
|
4
|
+
["Afghanistan", "AF", "AFG", "004"],
|
5
|
+
["Åland", "AX", "ALA", "248"],
|
6
|
+
["Albania", "AL", "ALB", "008"],
|
7
|
+
["Algeria", "DZ", "DZA", "012"],
|
8
|
+
["American Samoa", "AS", "ASM", "016"],
|
9
|
+
["Andorra", "AD", "AND", "020"],
|
10
|
+
["Angola", "AO", "AGO", "024"],
|
11
|
+
["Anguilla", "AI", "AIA", "660"],
|
12
|
+
["Antarctica", "AQ", "ATA", "010"],
|
13
|
+
["Antigua and Barbuda", "AG", "ATG", "028"],
|
14
|
+
["Argentina", "AR", "ARG", "032"],
|
15
|
+
["Armenia", "AM", "ARM", "051"],
|
16
|
+
["Aruba", "AW", "ABW", "533"],
|
17
|
+
["Australia", "AU", "AUS", "036"],
|
18
|
+
["Austria", "AT", "AUT", "040"],
|
19
|
+
["Azerbaijan", "AZ", "AZE", "031"],
|
20
|
+
["Bahamas", "BS", "BHS", "044"],
|
21
|
+
["Bahrain", "BH", "BHR", "048"],
|
22
|
+
["Bangladesh", "BD", "BGD", "050"],
|
23
|
+
["Barbados", "BB", "BRB", "052"],
|
24
|
+
["Belarus", "BY", "BLR", "112"],
|
25
|
+
["Belgium", "BE", "BEL", "056"],
|
26
|
+
["Belize", "BZ", "BLZ", "084"],
|
27
|
+
["Benin", "BJ", "BEN", "204"],
|
28
|
+
["Bermuda", "BM", "BMU", "060"],
|
29
|
+
["Bhutan", "BT", "BTN", "064"],
|
30
|
+
["Bolivia", "BO", "BOL", "068"],
|
31
|
+
["Bosnia and Herzegovina", "BA", "BIH", "070"],
|
32
|
+
["Botswana", "BW", "BWA", "072"],
|
33
|
+
["Bouvet Island", "BV", "BVT", "074"],
|
34
|
+
["Brazil", "BR", "BRA", "076"],
|
35
|
+
["British Indian Ocean Territory", "IO", "IOT", "086"],
|
36
|
+
["Brunei Darussalam", "BN", "BRN", "096"],
|
37
|
+
["Bulgaria", "BG", "BGR", "100"],
|
38
|
+
["Burkina Faso", "BF", "BFA", "854"],
|
39
|
+
["Burundi", "BI", "BDI", "108"],
|
40
|
+
["Cambodia", "KH", "KHM", "116"],
|
41
|
+
["Cameroon", "CM", "CMR", "120"],
|
42
|
+
["Canada", "CA", "CAN", "124"],
|
43
|
+
["Cape Verde", "CV", "CPV", "132"],
|
44
|
+
["Cayman Islands", "KY", "CYM", "136"],
|
45
|
+
["Central African Republic", "CF", "CAF", "140"],
|
46
|
+
["Chad", "TD", "TCD", "148"],
|
47
|
+
["Chile", "CL", "CHL", "152"],
|
48
|
+
["China", "CN", "CHN", "156"],
|
49
|
+
["Christmas Island", "CX", "CXR", "162"],
|
50
|
+
["Cocos (Keeling) Islands", "CC", "CCK", "166"],
|
51
|
+
["Colombia", "CO", "COL", "170"],
|
52
|
+
["Comoros", "KM", "COM", "174"],
|
53
|
+
["Congo (Brazzaville)", "CG", "COG", "178"],
|
54
|
+
["Congo (Kinshasa)", "CD", "COD", "180"],
|
55
|
+
["Cook Islands", "CK", "COK", "184"],
|
56
|
+
["Costa Rica", "CR", "CRI", "188"],
|
57
|
+
["Côte d'Ivoire", "CI", "CIV", "384"],
|
58
|
+
["Croatia", "HR", "HRV", "191"],
|
59
|
+
["Cuba", "CU", "CUB", "192"],
|
60
|
+
["Cyprus", "CY", "CYP", "196"],
|
61
|
+
["Czech Republic", "CZ", "CZE", "203"],
|
62
|
+
["Denmark", "DK", "DNK", "208"],
|
63
|
+
["Djibouti", "DJ", "DJI", "262"],
|
64
|
+
["Dominica", "DM", "DMA", "212"],
|
65
|
+
["Dominican Republic", "DO", "DOM", "214"],
|
66
|
+
["Ecuador", "EC", "ECU", "218"],
|
67
|
+
["Egypt", "EG", "EGY", "818"],
|
68
|
+
["El Salvador", "SV", "SLV", "222"],
|
69
|
+
["Equatorial Guinea", "GQ", "GNQ", "226"],
|
70
|
+
["Eritrea", "ER", "ERI", "232"],
|
71
|
+
["Estonia", "EE", "EST", "233"],
|
72
|
+
["Ethiopia", "ET", "ETH", "231"],
|
73
|
+
["Falkland Islands", "FK", "FLK", "238"],
|
74
|
+
["Faroe Islands", "FO", "FRO", "234"],
|
75
|
+
["Fiji", "FJ", "FJI", "242"],
|
76
|
+
["Finland", "FI", "FIN", "246"],
|
77
|
+
["France", "FR", "FRA", "250"],
|
78
|
+
["French Guiana", "GF", "GUF", "254"],
|
79
|
+
["French Polynesia", "PF", "PYF", "258"],
|
80
|
+
["French Southern Lands", "TF", "ATF", "260"],
|
81
|
+
["Gabon", "GA", "GAB", "266"],
|
82
|
+
["Gambia", "GM", "GMB", "270"],
|
83
|
+
["Georgia", "GE", "GEO", "268"],
|
84
|
+
["Germany", "DE", "DEU", "276"],
|
85
|
+
["Ghana", "GH", "GHA", "288"],
|
86
|
+
["Gibraltar", "GI", "GIB", "292"],
|
87
|
+
["Greece", "GR", "GRC", "300"],
|
88
|
+
["Greenland", "GL", "GRL", "304"],
|
89
|
+
["Grenada", "GD", "GRD", "308"],
|
90
|
+
["Guadeloupe", "GP", "GLP", "312"],
|
91
|
+
["Guam", "GU", "GUM", "316"],
|
92
|
+
["Guatemala", "GT", "GTM", "320"],
|
93
|
+
["Guernsey", "GG", "GGY", "831"],
|
94
|
+
["Guinea", "GN", "GIN", "324"],
|
95
|
+
["Guinea-Bissau", "GW", "GNB", "624"],
|
96
|
+
["Guyana", "GY", "GUY", "328"],
|
97
|
+
["Haiti", "HT", "HTI", "332"],
|
98
|
+
["Heard and McDonald Islands", "HM", "HMD", "334"],
|
99
|
+
["Honduras", "HN", "HND", "340"],
|
100
|
+
["Hong Kong", "HK", "HKG", "344"],
|
101
|
+
["Hungary", "HU", "HUN", "348"],
|
102
|
+
["Iceland", "IS", "ISL", "352"],
|
103
|
+
["India", "IN", "IND", "356"],
|
104
|
+
["Indonesia", "ID", "IDN", "360"],
|
105
|
+
["Iran", "IR", "IRN", "364"],
|
106
|
+
["Iraq", "IQ", "IRQ", "368"],
|
107
|
+
["Ireland", "IE", "IRL", "372"],
|
108
|
+
["Isle of Man", "IM", "IMN", "833"],
|
109
|
+
["Israel", "IL", "ISR", "376"],
|
110
|
+
["Italy", "IT", "ITA", "380"],
|
111
|
+
["Jamaica", "JM", "JAM", "388"],
|
112
|
+
["Japan", "JP", "JPN", "392"],
|
113
|
+
["Jersey", "JE", "JEY", "832"],
|
114
|
+
["Jordan", "JO", "JOR", "400"],
|
115
|
+
["Kazakhstan", "KZ", "KAZ", "398"],
|
116
|
+
["Kenya", "KE", "KEN", "404"],
|
117
|
+
["Kiribati", "KI", "KIR", "296"],
|
118
|
+
["Korea, North", "KP", "PRK", "408"],
|
119
|
+
["Korea, South", "KR", "KOR", "410"],
|
120
|
+
["Kuwait", "KW", "KWT", "414"],
|
121
|
+
["Kyrgyzstan", "KG", "KGZ", "417"],
|
122
|
+
["Laos", "LA", "LAO", "418"],
|
123
|
+
["Latvia", "LV", "LVA", "428"],
|
124
|
+
["Lebanon", "LB", "LBN", "422"],
|
125
|
+
["Lesotho", "LS", "LSO", "426"],
|
126
|
+
["Liberia", "LR", "LBR", "430"],
|
127
|
+
["Libya", "LY", "LBY", "434"],
|
128
|
+
["Liechtenstein", "LI", "LIE", "438"],
|
129
|
+
["Lithuania", "LT", "LTU", "440"],
|
130
|
+
["Luxembourg", "LU", "LUX", "442"],
|
131
|
+
["Macau", "MO", "MAC", "446"],
|
132
|
+
["Macedonia", "MK", "MKD", "807"],
|
133
|
+
["Madagascar", "MG", "MDG", "450"],
|
134
|
+
["Malawi", "MW", "MWI", "454"],
|
135
|
+
["Malaysia", "MY", "MYS", "458"],
|
136
|
+
["Maldives", "MV", "MDV", "462"],
|
137
|
+
["Mali", "ML", "MLI", "466"],
|
138
|
+
["Malta", "MT", "MLT", "470"],
|
139
|
+
["Marshall Islands", "MH", "MHL", "584"],
|
140
|
+
["Martinique", "MQ", "MTQ", "474"],
|
141
|
+
["Mauritania", "MR", "MRT", "478"],
|
142
|
+
["Mauritius", "MU", "MUS", "480"],
|
143
|
+
["Mayotte", "YT", "MYT", "175"],
|
144
|
+
["Mexico", "MX", "MEX", "484"],
|
145
|
+
["Micronesia", "FM", "FSM", "583"],
|
146
|
+
["Moldova", "MD", "MDA", "498"],
|
147
|
+
["Monaco", "MC", "MCO", "492"],
|
148
|
+
["Mongolia", "MN", "MNG", "496"],
|
149
|
+
["Montenegro", "ME", "MNE", "499"],
|
150
|
+
["Montserrat", "MS", "MSR", "500"],
|
151
|
+
["Morocco", "MA", "MAR", "504"],
|
152
|
+
["Mozambique", "MZ", "MOZ", "508"],
|
153
|
+
["Myanmar", "MM", "MMR", "104"],
|
154
|
+
["Namibia", "NA", "NAM", "516"],
|
155
|
+
["Nauru", "NR", "NRU", "520"],
|
156
|
+
["Nepal", "NP", "NPL", "524"],
|
157
|
+
["Netherlands", "NL", "NLD", "528"],
|
158
|
+
["Netherlands Antilles", "AN", "ANT", "530"],
|
159
|
+
["New Caledonia", "NC", "NCL", "540"],
|
160
|
+
["New Zealand", "NZ", "NZL", "554"],
|
161
|
+
["Nicaragua", "NI", "NIC", "558"],
|
162
|
+
["Niger", "NE", "NER", "562"],
|
163
|
+
["Nigeria", "NG", "NGA", "566"],
|
164
|
+
["Niue", "NU", "NIU", "570"],
|
165
|
+
["Norfolk Island", "NF", "NFK", "574"],
|
166
|
+
["Northern Mariana Islands", "MP", "MNP", "580"],
|
167
|
+
["Norway", "NO", "NOR", "578"],
|
168
|
+
["Oman", "OM", "OMN", "512"],
|
169
|
+
["Pakistan", "PK", "PAK", "586"],
|
170
|
+
["Palau", "PW", "PLW", "585"],
|
171
|
+
["Palestine", "PS", "PSE", "275"],
|
172
|
+
["Panama", "PA", "PAN", "591"],
|
173
|
+
["Papua New Guinea", "PG", "PNG", "598"],
|
174
|
+
["Paraguay", "PY", "PRY", "600"],
|
175
|
+
["Peru", "PE", "PER", "604"],
|
176
|
+
["Philippines", "PH", "PHL", "608"],
|
177
|
+
["Pitcairn", "PN", "PCN", "612"],
|
178
|
+
["Poland", "PL", "POL", "616"],
|
179
|
+
["Portugal", "PT", "PRT", "620"],
|
180
|
+
["Puerto Rico", "PR", "PRI", "630"],
|
181
|
+
["Qatar", "QA", "QAT", "634"],
|
182
|
+
["Reunion", "RE", "REU", "638"],
|
183
|
+
["Romania", "RO", "ROU", "642"],
|
184
|
+
["Russian Federation", "RU", "RUS", "643"],
|
185
|
+
["Rwanda", "RW", "RWA", "646"],
|
186
|
+
["Saint Barthélemy", "BL", "BLM", "652"],
|
187
|
+
["Saint Helena", "SH", "SHN", "654"],
|
188
|
+
["Saint Kitts and Nevis", "KN", "KNA", "659"],
|
189
|
+
["Saint Lucia", "LC", "LCA", "662"],
|
190
|
+
["Saint Martin (French part)", "MF", "MAF", "663"],
|
191
|
+
["Saint Pierre and Miquelon", "PM", "SPM", "666"],
|
192
|
+
["Saint Vincent and the Grenadines", "VC", "VCT", "670"],
|
193
|
+
["Samoa", "WS", "WSM", "882"],
|
194
|
+
["San Marino", "SM", "SMR", "674"],
|
195
|
+
["Sao Tome and Principe", "ST", "STP", "678"],
|
196
|
+
["Saudi Arabia", "SA", "SAU", "682"],
|
197
|
+
["Senegal", "SN", "SEN", "686"],
|
198
|
+
["Serbia", "RS", "SRB", "688"],
|
199
|
+
["Seychelles", "SC", "SYC", "690"],
|
200
|
+
["Sierra Leone", "SL", "SLE", "694"],
|
201
|
+
["Singapore", "SG", "SGP", "702"],
|
202
|
+
["Slovakia", "SK", "SVK", "703"],
|
203
|
+
["Slovenia", "SI", "SVN", "705"],
|
204
|
+
["Solomon Islands", "SB", "SLB", "090"],
|
205
|
+
["Somalia", "SO", "SOM", "706"],
|
206
|
+
["South Africa", "ZA", "ZAF", "710"],
|
207
|
+
["South Georgia and South Sandwich Islands", "GS", "SGS", "239"],
|
208
|
+
["Spain", "ES", "ESP", "724"],
|
209
|
+
["Sri Lanka", "LK", "LKA", "144"],
|
210
|
+
["Sudan", "SD", "SDN", "736"],
|
211
|
+
["Suriname", "SR", "SUR", "740"],
|
212
|
+
["Svalbard and Jan Mayen Islands", "SJ", "SJM", "744"],
|
213
|
+
["Swaziland", "SZ", "SWZ", "748"],
|
214
|
+
["Sweden", "SE", "SWE", "752"],
|
215
|
+
["Switzerland", "CH", "CHE", "756"],
|
216
|
+
["Syria", "SY", "SYR", "760"],
|
217
|
+
["Taiwan", "TW", "TWN", "158"],
|
218
|
+
["Tajikistan", "TJ", "TJK", "762"],
|
219
|
+
["Tanzania", "TZ", "TZA", "834"],
|
220
|
+
["Thailand", "TH", "THA", "764"],
|
221
|
+
["Timor-Leste", "TL", "TLS", "626"],
|
222
|
+
["Togo", "TG", "TGO", "768"],
|
223
|
+
["Tokelau", "TK", "TKL", "772"],
|
224
|
+
["Tonga", "TO", "TON", "776"],
|
225
|
+
["Trinidad and Tobago", "TT", "TTO", "780"],
|
226
|
+
["Tunisia", "TN", "TUN", "788"],
|
227
|
+
["Turkey", "TR", "TUR", "792"],
|
228
|
+
["Turkmenistan", "TM", "TKM", "795"],
|
229
|
+
["Turks and Caicos Islands", "TC", "TCA", "796"],
|
230
|
+
["Tuvalu", "TV", "TUV", "798"],
|
231
|
+
["Uganda", "UG", "UGA", "800"],
|
232
|
+
["Ukraine", "UA", "UKR", "804"],
|
233
|
+
["United Arab Emirates", "AE", "ARE", "784"],
|
234
|
+
["United Kingdom", "GB", "GBR", "826"],
|
235
|
+
["United States Minor Outlying Islands", "UM", "UMI", "581"],
|
236
|
+
["United States of America", "US", "USA", "840"],
|
237
|
+
["Uruguay", "UY", "URY", "858"],
|
238
|
+
["Uzbekistan", "UZ", "UZB", "860"],
|
239
|
+
["Vanuatu", "VU", "VUT", "548"],
|
240
|
+
["Vatican City", "VA", "VAT", "336"],
|
241
|
+
["Venezuela", "VE", "VEN", "862"],
|
242
|
+
["Vietnam", "VN", "VNM", "704"],
|
243
|
+
["Virgin Islands, British", "VG", "VGB", "092"],
|
244
|
+
["Virgin Islands, U.S.", "VI", "VIR", "850"],
|
245
|
+
["Wallis and Futuna Islands", "WF", "WLF", "876"],
|
246
|
+
["Western Sahara", "EH", "ESH", "732"],
|
247
|
+
["Yemen", "YE", "YEM", "887"],
|
248
|
+
["Zambia", "ZM", "ZMB", "894"],
|
249
|
+
["Zimbabwe", "ZW", "ZWE", "716"]]
|
250
|
+
end
|
251
|
+
end
|
data/lib/braintree/customer.rb
CHANGED
@@ -134,7 +134,7 @@ module Braintree
|
|
134
134
|
#
|
135
135
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
|
136
136
|
def sale(transaction_attributes)
|
137
|
-
warn "[DEPRECATED] sale as an instance method is deprecated. Please use
|
137
|
+
warn "[DEPRECATED] sale as an instance method is deprecated. Please use Customer.sale"
|
138
138
|
@gateway.transaction.sale(transaction_attributes.merge(:customer_id => id))
|
139
139
|
end
|
140
140
|
|
@@ -142,7 +142,7 @@ module Braintree
|
|
142
142
|
#
|
143
143
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/create_from_vault
|
144
144
|
def sale!(transaction_attributes)
|
145
|
-
warn "[DEPRECATED] sale! as an instance method is deprecated. Please use
|
145
|
+
warn "[DEPRECATED] sale! as an instance method is deprecated. Please use Customer.sale!"
|
146
146
|
return_object_or_raise(:transaction) { sale(transaction_attributes) }
|
147
147
|
end
|
148
148
|
|
@@ -155,7 +155,7 @@ module Braintree
|
|
155
155
|
#
|
156
156
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update
|
157
157
|
def update(attributes)
|
158
|
-
warn "[DEPRECATED] update as an instance method is deprecated. Please use
|
158
|
+
warn "[DEPRECATED] update as an instance method is deprecated. Please use Customer.update"
|
159
159
|
result = @gateway.customer.update(id, attributes)
|
160
160
|
if result.success?
|
161
161
|
copy_instance_variables_from_object result.customer
|
@@ -167,7 +167,7 @@ module Braintree
|
|
167
167
|
#
|
168
168
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/customers/update
|
169
169
|
def update!(attributes)
|
170
|
-
warn "[DEPRECATED] update! as an instance method is deprecated. Please use
|
170
|
+
warn "[DEPRECATED] update! as an instance method is deprecated. Please use Customer.update!"
|
171
171
|
return_object_or_raise(:customer) { update(attributes) }
|
172
172
|
end
|
173
173
|
|
@@ -93,6 +93,7 @@ module Braintree
|
|
93
93
|
IdIsInUse = "81902"
|
94
94
|
InconsistentNumberOfBillingCycles = "91908"
|
95
95
|
InconsistentStartDate = "91917"
|
96
|
+
InvalidRequestFormat = "91921"
|
96
97
|
MerchantAccountIdIsInvalid = "91901"
|
97
98
|
NumberOfBillingCyclesCannotBeBlank = "91912"
|
98
99
|
NumberOfBillingCyclesIsTooSmall = "91909"
|
@@ -2,7 +2,7 @@ module Braintree
|
|
2
2
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/general/result_objects
|
3
3
|
class ErrorResult
|
4
4
|
|
5
|
-
attr_reader :credit_card_verification, :transaction, :errors, :params, :message
|
5
|
+
attr_reader :credit_card_verification, :transaction, :subscription, :errors, :params, :message
|
6
6
|
|
7
7
|
def initialize(gateway, data) # :nodoc:
|
8
8
|
@gateway = gateway
|
@@ -10,6 +10,7 @@ module Braintree
|
|
10
10
|
@credit_card_verification = CreditCardVerification._new(data[:verification]) if data[:verification]
|
11
11
|
@message = data[:message]
|
12
12
|
@transaction = Transaction._new(gateway, data[:transaction]) if data[:transaction]
|
13
|
+
@subscription = Subscription._new(gateway, data[:subscription]) if data[:subscription]
|
13
14
|
@errors = Errors.new(data[:errors])
|
14
15
|
end
|
15
16
|
|
@@ -20,10 +20,11 @@ module Braintree
|
|
20
20
|
|
21
21
|
attr_reader :days_past_due, :price, :plan_id, :id, :status, :payment_method_token, :merchant_account_id
|
22
22
|
attr_reader :first_billing_date, :next_billing_date, :billing_period_start_date, :billing_period_end_date
|
23
|
+
attr_reader :paid_through_date, :balance
|
23
24
|
attr_reader :trial_period, :trial_duration, :trial_duration_unit
|
24
25
|
attr_reader :failure_count
|
25
26
|
attr_reader :transactions
|
26
|
-
attr_reader :
|
27
|
+
attr_reader :next_billing_period_amount
|
27
28
|
attr_reader :number_of_billing_cycles, :billing_day_of_month
|
28
29
|
attr_reader :add_ons, :discounts
|
29
30
|
|
@@ -59,12 +60,18 @@ module Braintree
|
|
59
60
|
def initialize(gateway, attributes) # :nodoc:
|
60
61
|
@gateway = gateway
|
61
62
|
set_instance_variables_from_hash(attributes)
|
63
|
+
@balance = Util.to_big_decimal(balance)
|
62
64
|
@price = Util.to_big_decimal(price)
|
63
65
|
transactions.map! { |attrs| Transaction._new(gateway, attrs) }
|
64
66
|
add_ons.map! { |attrs| AddOn._new(attrs) }
|
65
67
|
discounts.map! { |attrs| Discount._new(attrs) }
|
66
68
|
end
|
67
69
|
|
70
|
+
def next_bill_amount
|
71
|
+
warn "[DEPRECATED] Subscription.next_bill_amount is deprecated. Please use Subscription.next_billing_period_amount"
|
72
|
+
@next_bill_amount
|
73
|
+
end
|
74
|
+
|
68
75
|
def never_expires?
|
69
76
|
@never_expires
|
70
77
|
end
|
@@ -64,7 +64,7 @@ module Braintree
|
|
64
64
|
:trial_duration,
|
65
65
|
:trial_duration_unit,
|
66
66
|
:trial_period,
|
67
|
-
{:options => [:do_not_inherit_add_ons_or_discounts, :start_immediately]}
|
67
|
+
{:options => [:do_not_inherit_add_ons_or_discounts, :start_immediately]}
|
68
68
|
] + _add_on_discount_signature
|
69
69
|
end
|
70
70
|
|
@@ -77,7 +77,11 @@ module Braintree
|
|
77
77
|
:payment_method_token,
|
78
78
|
:plan_id,
|
79
79
|
:price,
|
80
|
-
{:options => [
|
80
|
+
{:options => [
|
81
|
+
:prorate_charges,
|
82
|
+
:replace_all_add_ons_and_discounts,
|
83
|
+
:revert_subscription_on_proration_failure
|
84
|
+
]}
|
81
85
|
] + _add_on_discount_signature
|
82
86
|
end
|
83
87
|
|
@@ -55,7 +55,7 @@ module Braintree
|
|
55
55
|
attr_reader :processor_response_code
|
56
56
|
# The response text from the processor.
|
57
57
|
attr_reader :processor_response_text
|
58
|
-
attr_reader :
|
58
|
+
attr_reader :refund_ids, :refunded_transaction_id
|
59
59
|
attr_reader :settlement_batch_id
|
60
60
|
# See Transaction::Status
|
61
61
|
attr_reader :status
|
@@ -181,7 +181,7 @@ module Braintree
|
|
181
181
|
#
|
182
182
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/refund
|
183
183
|
def refund(amount = nil)
|
184
|
-
warn "[DEPRECATED] refund as an instance method is deprecated. Please use
|
184
|
+
warn "[DEPRECATED] refund as an instance method is deprecated. Please use Transaction.refund"
|
185
185
|
result = @gateway.transaction.refund(id, amount)
|
186
186
|
|
187
187
|
if result.success?
|
@@ -196,11 +196,16 @@ module Braintree
|
|
196
196
|
!@refund_id.nil?
|
197
197
|
end
|
198
198
|
|
199
|
+
def refund_id
|
200
|
+
warn "[DEPRECATED] Transaction.refund_id is deprecated. Please use TransparentRedirect.refund_ids"
|
201
|
+
@refund_id
|
202
|
+
end
|
203
|
+
|
199
204
|
# Deprecated. Use Braintree::Transaction.submit_for_settlement
|
200
205
|
#
|
201
206
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/submit_for_settlement
|
202
207
|
def submit_for_settlement(amount = nil)
|
203
|
-
warn "[DEPRECATED] submit_for_settlement as an instance method is deprecated. Please use
|
208
|
+
warn "[DEPRECATED] submit_for_settlement as an instance method is deprecated. Please use Transaction.submit_for_settlement"
|
204
209
|
result = @gateway.transaction.submit_for_settlement(id, amount)
|
205
210
|
if result.success?
|
206
211
|
copy_instance_variables_from_object result.transaction
|
@@ -212,7 +217,7 @@ module Braintree
|
|
212
217
|
#
|
213
218
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/submit_for_settlement
|
214
219
|
def submit_for_settlement!(amount = nil)
|
215
|
-
warn "[DEPRECATED] submit_for_settlement! as an instance method is deprecated. Please use
|
220
|
+
warn "[DEPRECATED] submit_for_settlement! as an instance method is deprecated. Please use Transaction.submit_for_settlement!"
|
216
221
|
return_object_or_raise(:transaction) { submit_for_settlement(amount) }
|
217
222
|
end
|
218
223
|
|
@@ -256,7 +261,7 @@ module Braintree
|
|
256
261
|
#
|
257
262
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/void
|
258
263
|
def void
|
259
|
-
warn "[DEPRECATED] void as an instance method is deprecated. Please use
|
264
|
+
warn "[DEPRECATED] void as an instance method is deprecated. Please use Transaction.void"
|
260
265
|
result = @gateway.transaction.void(id)
|
261
266
|
if result.success?
|
262
267
|
copy_instance_variables_from_object result.transaction
|
@@ -268,7 +273,7 @@ module Braintree
|
|
268
273
|
#
|
269
274
|
# See http://www.braintreepaymentsolutions.com/docs/ruby/transactions/void
|
270
275
|
def void!
|
271
|
-
warn "[DEPRECATED] void! as an instance method is deprecated. Please use
|
276
|
+
warn "[DEPRECATED] void! as an instance method is deprecated. Please use Transaction.void!"
|
272
277
|
return_object_or_raise(:transaction) { void }
|
273
278
|
end
|
274
279
|
|
data/lib/braintree/version.rb
CHANGED
@@ -28,9 +28,11 @@ describe Braintree::Subscription do
|
|
28
28
|
result.subscription.next_billing_date.should match(date_format)
|
29
29
|
result.subscription.billing_period_start_date.should match(date_format)
|
30
30
|
result.subscription.billing_period_end_date.should match(date_format)
|
31
|
+
result.subscription.paid_through_date.should match(date_format)
|
31
32
|
|
32
33
|
result.subscription.failure_count.should == 0
|
33
34
|
result.subscription.next_bill_amount.should == "12.34"
|
35
|
+
result.subscription.next_billing_period_amount.should == "12.34"
|
34
36
|
result.subscription.payment_method_token.should == @credit_card.token
|
35
37
|
end
|
36
38
|
|
@@ -585,46 +587,82 @@ describe Braintree::Subscription do
|
|
585
587
|
result.subscription.price.should == BigDecimal.new("9999.88")
|
586
588
|
end
|
587
589
|
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
590
|
+
context "proration" do
|
591
|
+
it "prorates if there is a charge (because merchant has proration option enabled in control panel)" do
|
592
|
+
result = Braintree::Subscription.update(@subscription.id,
|
593
|
+
:price => @subscription.price.to_f + 1
|
594
|
+
)
|
592
595
|
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
596
|
+
result.success?.should == true
|
597
|
+
result.subscription.price.to_f.should == @subscription.price.to_f + 1
|
598
|
+
result.subscription.transactions.size.should == @subscription.transactions.size + 1
|
599
|
+
end
|
597
600
|
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
601
|
+
it "allows the user to force proration if there is a charge" do
|
602
|
+
result = Braintree::Subscription.update(@subscription.id,
|
603
|
+
:price => @subscription.price.to_f + 1,
|
604
|
+
:options => { :prorate_charges => true }
|
605
|
+
)
|
603
606
|
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
607
|
+
result.success?.should == true
|
608
|
+
result.subscription.price.to_f.should == @subscription.price.to_f + 1
|
609
|
+
result.subscription.transactions.size.should == @subscription.transactions.size + 1
|
610
|
+
end
|
608
611
|
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
612
|
+
it "allows the user to prevent proration if there is a charge" do
|
613
|
+
result = Braintree::Subscription.update(@subscription.id,
|
614
|
+
:price => @subscription.price.to_f + 1,
|
615
|
+
:options => { :prorate_charges => false }
|
616
|
+
)
|
614
617
|
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
618
|
+
result.success?.should == true
|
619
|
+
result.subscription.price.to_f.should == @subscription.price.to_f + 1
|
620
|
+
result.subscription.transactions.size.should == @subscription.transactions.size
|
621
|
+
end
|
619
622
|
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
623
|
+
it "doesn't prorate if price decreases" do
|
624
|
+
result = Braintree::Subscription.update(@subscription.id,
|
625
|
+
:price => @subscription.price.to_f - 1
|
626
|
+
)
|
624
627
|
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
+
result.success?.should == true
|
629
|
+
result.subscription.price.to_f.should == @subscription.price.to_f - 1
|
630
|
+
result.subscription.transactions.size.should == @subscription.transactions.size
|
631
|
+
end
|
632
|
+
|
633
|
+
it "updates the subscription if the proration fails and revert_subscription_on_proration_failure => false" do
|
634
|
+
result = Braintree::Subscription.update(@subscription.id,
|
635
|
+
:price => @subscription.price.to_f + 2100,
|
636
|
+
:options => {
|
637
|
+
:revert_subscription_on_proration_failure => false
|
638
|
+
}
|
639
|
+
)
|
640
|
+
|
641
|
+
result.success?.should == true
|
642
|
+
result.subscription.price.to_f.should == @subscription.price.to_f + 2100
|
643
|
+
|
644
|
+
result.subscription.transactions.size.should == @subscription.transactions.size + 1
|
645
|
+
transaction = result.subscription.transactions.first
|
646
|
+
transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
647
|
+
result.subscription.balance.should == transaction.amount
|
648
|
+
end
|
649
|
+
|
650
|
+
it "does not update the subscription if the proration fails and revert_subscription_on_proration_failure => true" do
|
651
|
+
result = Braintree::Subscription.update(@subscription.id,
|
652
|
+
:price => @subscription.price.to_f + 2100,
|
653
|
+
:options => {
|
654
|
+
:revert_subscription_on_proration_failure => true
|
655
|
+
}
|
656
|
+
)
|
657
|
+
|
658
|
+
result.success?.should == false
|
659
|
+
result.subscription.price.to_f.should == @subscription.price.to_f
|
660
|
+
|
661
|
+
result.subscription.transactions.size.should == @subscription.transactions.size + 1
|
662
|
+
transaction = result.subscription.transactions.first
|
663
|
+
transaction.status.should == Braintree::Transaction::Status::ProcessorDeclined
|
664
|
+
result.subscription.balance.should == 0
|
665
|
+
end
|
628
666
|
end
|
629
667
|
end
|
630
668
|
|
@@ -1050,6 +1088,7 @@ describe Braintree::Subscription do
|
|
1050
1088
|
collection.should_not include(active_subscription)
|
1051
1089
|
collection.each do |s|
|
1052
1090
|
s.status.should == Braintree::Subscription::Status::PastDue
|
1091
|
+
s.balance.should == BigDecimal.new("6.00")
|
1053
1092
|
end
|
1054
1093
|
end
|
1055
1094
|
|
@@ -562,6 +562,14 @@ describe Braintree::Transaction, "search" do
|
|
562
562
|
end
|
563
563
|
|
564
564
|
collection.maximum_size.should == 0
|
565
|
+
|
566
|
+
collection = Braintree::Transaction.search do |search|
|
567
|
+
search.id.is transaction.id
|
568
|
+
search.created_at.is created_at
|
569
|
+
end
|
570
|
+
|
571
|
+
collection.maximum_size.should == 1
|
572
|
+
collection.first.id.should == transaction.id
|
565
573
|
end
|
566
574
|
|
567
575
|
it "searches on created_at in local time" do
|
@@ -555,12 +555,13 @@ describe Braintree::Transaction do
|
|
555
555
|
result.transaction.type.should == "credit"
|
556
556
|
end
|
557
557
|
|
558
|
-
it "
|
558
|
+
it "allows multiple partial refunds" do
|
559
559
|
transaction = create_transaction_to_refund
|
560
|
-
Braintree::Transaction.refund(transaction.id, transaction.amount / 2)
|
561
|
-
|
562
|
-
|
563
|
-
|
560
|
+
transaction_1 = Braintree::Transaction.refund(transaction.id, transaction.amount / 2).transaction
|
561
|
+
transaction_2 = Braintree::Transaction.refund(transaction.id, transaction.amount / 2).transaction
|
562
|
+
|
563
|
+
transaction = Braintree::Transaction.find(transaction.id)
|
564
|
+
transaction.refund_ids.sort.should == [transaction_1.id, transaction_2.id].sort
|
564
565
|
end
|
565
566
|
end
|
566
567
|
|
@@ -1390,14 +1391,6 @@ describe Braintree::Transaction do
|
|
1390
1391
|
result.success?.should == true
|
1391
1392
|
result.new_transaction.type.should == "credit"
|
1392
1393
|
end
|
1393
|
-
|
1394
|
-
it "does not allow multiple refunds" do
|
1395
|
-
transaction = create_transaction_to_refund
|
1396
|
-
transaction.refund(transaction.amount / 2)
|
1397
|
-
result = transaction.refund(BigDecimal.new("1"))
|
1398
|
-
result.success?.should == false
|
1399
|
-
result.errors.for(:transaction).on(:base)[0].code.should == Braintree::ErrorCodes::Transaction::HasAlreadyBeenRefunded
|
1400
|
-
end
|
1401
1394
|
end
|
1402
1395
|
|
1403
1396
|
it "returns a successful result if successful" do
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 2
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 2.
|
7
|
+
- 6
|
8
|
+
- 0
|
9
|
+
version: 2.6.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Braintree Payment Solutions
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-09-
|
17
|
+
date: 2010-09-20 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- README.rdoc
|
42
42
|
- LICENSE
|
43
43
|
- lib/braintree/add_on.rb
|
44
|
+
- lib/braintree/address/country_names.rb
|
44
45
|
- lib/braintree/address.rb
|
45
46
|
- lib/braintree/address_gateway.rb
|
46
47
|
- lib/braintree/advanced_search.rb
|