Class: ProcessOut::Subscription
- Inherits:
-
Object
- Object
- ProcessOut::Subscription
- Defined in:
- lib/processout/subscription.rb
Instance Attribute Summary collapse
-
#activated ⇒ Object
Returns the value of attribute activated.
-
#activated_at ⇒ Object
Returns the value of attribute activated_at.
-
#active ⇒ Object
Returns the value of attribute active.
-
#amount ⇒ Object
Returns the value of attribute amount.
-
#cancel_at ⇒ Object
Returns the value of attribute cancel_at.
-
#cancel_url ⇒ Object
Returns the value of attribute cancel_url.
-
#canceled ⇒ Object
Returns the value of attribute canceled.
-
#cancellation_reason ⇒ Object
Returns the value of attribute cancellation_reason.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#currency ⇒ Object
Returns the value of attribute currency.
-
#customer ⇒ Object
Returns the value of attribute customer.
-
#id ⇒ Object
Returns the value of attribute id.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#iterate_at ⇒ Object
Returns the value of attribute iterate_at.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#name ⇒ Object
Returns the value of attribute name.
-
#pending_cancellation ⇒ Object
Returns the value of attribute pending_cancellation.
-
#plan ⇒ Object
Returns the value of attribute plan.
-
#project ⇒ Object
Returns the value of attribute project.
-
#return_url ⇒ Object
Returns the value of attribute return_url.
-
#sandbox ⇒ Object
Returns the value of attribute sandbox.
-
#token ⇒ Object
Returns the value of attribute token.
-
#trial_end_at ⇒ Object
Returns the value of attribute trial_end_at.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#all(options = {}) ⇒ Object
Get all the subscriptions.
-
#apply_coupon(coupon_id, options = {}) ⇒ Object
Apply a coupon on the subscription.
-
#apply_source(source, options = {}) ⇒ Object
Apply a source to the subscription to activate or update the subscription’s source.
-
#cancel(cancellation_reason, options = {}) ⇒ Object
Cancel a subscription.
-
#cancel_at_date(cancel_at, cancellation_reason, options = {}) ⇒ Object
Schedule the cancellation of the subscription.
-
#create(customer_id, options = {}) ⇒ Object
Create a new subscription for the given customer.
-
#create_from_plan(customer_id, plan_id, options = {}) ⇒ Object
Create a new subscription for the customer from the given plan ID.
-
#fetch_customer(options = {}) ⇒ Object
Get the customer owning the subscription.
-
#fetch_discounts(options = {}) ⇒ Object
Get the discounts applied to the subscription.
-
#fetch_transactions(options = {}) ⇒ Object
Get the subscriptions past transactions.
-
#fill_with_data(data) ⇒ Object
- Fills the object with data coming from the API Params:
data -
Hashof data coming from the API.
- Fills the object with data coming from the API Params:
-
#find(subscription_id, options = {}) ⇒ Object
Find a subscription by its ID.
-
#find_discount(discount_id, options = {}) ⇒ Object
Find a subscription’s discount by its ID.
-
#initialize(client, data = {}) ⇒ Subscription
constructor
- Initializes the Subscription object Params:
client ProcessOutclient instancedata-
data that can be used to fill the object.
- Initializes the Subscription object Params:
-
#new(data = {}) ⇒ Object
Create a new Subscription using the current client.
-
#remove_discount(discount_id, options = {}) ⇒ Object
Remove a discount applied to a subscription.
-
#update(prorate, options = {}) ⇒ Object
Update the subscription.
-
#update_plan(plan_id, prorate, options = {}) ⇒ Object
Update the subscription’s plan.
Constructor Details
#initialize(client, data = {}) ⇒ Subscription
Initializes the Subscription object Params:
client-
ProcessOutclient instance data-
data that can be used to fill the object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/processout/subscription.rb', line 165 def initialize(client, data = {}) @client = client @id = data.fetch(:id, "") @project = data.fetch(:project, nil) @plan = data.fetch(:plan, nil) @customer = data.fetch(:customer, nil) @token = data.fetch(:token, nil) @url = data.fetch(:url, "") @name = data.fetch(:name, "") @amount = data.fetch(:amount, "") @currency = data.fetch(:currency, "") = data.fetch(:metadata, Hash.new) @interval = data.fetch(:interval, "") @trial_end_at = data.fetch(:trial_end_at, "") @activated = data.fetch(:activated, false) @active = data.fetch(:active, false) @canceled = data.fetch(:canceled, false) @cancellation_reason = data.fetch(:cancellation_reason, "") @pending_cancellation = data.fetch(:pending_cancellation, false) @cancel_at = data.fetch(:cancel_at, "") @return_url = data.fetch(:return_url, "") @cancel_url = data.fetch(:cancel_url, "") @sandbox = data.fetch(:sandbox, false) @created_at = data.fetch(:created_at, "") @activated_at = data.fetch(:activated_at, "") @iterate_at = data.fetch(:iterate_at, "") end |
Instance Attribute Details
#activated ⇒ Object
Returns the value of attribute activated.
22 23 24 |
# File 'lib/processout/subscription.rb', line 22 def activated @activated end |
#activated_at ⇒ Object
Returns the value of attribute activated_at.
32 33 34 |
# File 'lib/processout/subscription.rb', line 32 def activated_at @activated_at end |
#active ⇒ Object
Returns the value of attribute active.
23 24 25 |
# File 'lib/processout/subscription.rb', line 23 def active @active end |
#amount ⇒ Object
Returns the value of attribute amount.
17 18 19 |
# File 'lib/processout/subscription.rb', line 17 def amount @amount end |
#cancel_at ⇒ Object
Returns the value of attribute cancel_at.
27 28 29 |
# File 'lib/processout/subscription.rb', line 27 def cancel_at @cancel_at end |
#cancel_url ⇒ Object
Returns the value of attribute cancel_url.
29 30 31 |
# File 'lib/processout/subscription.rb', line 29 def cancel_url @cancel_url end |
#canceled ⇒ Object
Returns the value of attribute canceled.
24 25 26 |
# File 'lib/processout/subscription.rb', line 24 def canceled @canceled end |
#cancellation_reason ⇒ Object
Returns the value of attribute cancellation_reason.
25 26 27 |
# File 'lib/processout/subscription.rb', line 25 def cancellation_reason @cancellation_reason end |
#created_at ⇒ Object
Returns the value of attribute created_at.
31 32 33 |
# File 'lib/processout/subscription.rb', line 31 def created_at @created_at end |
#currency ⇒ Object
Returns the value of attribute currency.
18 19 20 |
# File 'lib/processout/subscription.rb', line 18 def currency @currency end |
#customer ⇒ Object
Returns the value of attribute customer.
13 14 15 |
# File 'lib/processout/subscription.rb', line 13 def customer @customer end |
#id ⇒ Object
Returns the value of attribute id.
10 11 12 |
# File 'lib/processout/subscription.rb', line 10 def id @id end |
#interval ⇒ Object
Returns the value of attribute interval.
20 21 22 |
# File 'lib/processout/subscription.rb', line 20 def interval @interval end |
#iterate_at ⇒ Object
Returns the value of attribute iterate_at.
33 34 35 |
# File 'lib/processout/subscription.rb', line 33 def iterate_at @iterate_at end |
#metadata ⇒ Object
Returns the value of attribute metadata.
19 20 21 |
# File 'lib/processout/subscription.rb', line 19 def end |
#name ⇒ Object
Returns the value of attribute name.
16 17 18 |
# File 'lib/processout/subscription.rb', line 16 def name @name end |
#pending_cancellation ⇒ Object
Returns the value of attribute pending_cancellation.
26 27 28 |
# File 'lib/processout/subscription.rb', line 26 def pending_cancellation @pending_cancellation end |
#plan ⇒ Object
Returns the value of attribute plan.
12 13 14 |
# File 'lib/processout/subscription.rb', line 12 def plan @plan end |
#project ⇒ Object
Returns the value of attribute project.
11 12 13 |
# File 'lib/processout/subscription.rb', line 11 def project @project end |
#return_url ⇒ Object
Returns the value of attribute return_url.
28 29 30 |
# File 'lib/processout/subscription.rb', line 28 def return_url @return_url end |
#sandbox ⇒ Object
Returns the value of attribute sandbox.
30 31 32 |
# File 'lib/processout/subscription.rb', line 30 def sandbox @sandbox end |
#token ⇒ Object
Returns the value of attribute token.
14 15 16 |
# File 'lib/processout/subscription.rb', line 14 def token @token end |
#trial_end_at ⇒ Object
Returns the value of attribute trial_end_at.
21 22 23 |
# File 'lib/processout/subscription.rb', line 21 def trial_end_at @trial_end_at end |
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/processout/subscription.rb', line 15 def url @url end |
Instance Method Details
#all(options = {}) ⇒ Object
Get all the subscriptions. Params:
options-
Hashof options
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
# File 'lib/processout/subscription.rb', line 432 def all( = {}) request = Request.new(@client) path = "/subscriptions" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new a = Array.new body = response.body for v in body['subscriptions'] tmp = Subscription.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end |
#apply_coupon(coupon_id, options = {}) ⇒ Object
Apply a coupon on the subscription. Params:
coupon_id-
ID of the coupon
options-
Hashof options
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/processout/subscription.rb', line 334 def apply_coupon(coupon_id, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "/discounts" data = { "coupon_id" => coupon_id } response = Response.new(request.post(path, data, )) return_values = Array.new body = response.body body = body["discount"] discount = Discount.new(@client) return_values.push(discount.fill_with_data(body)) return_values[0] end |
#apply_source(source, options = {}) ⇒ Object
Apply a source to the subscription to activate or update the subscription’s source. Params:
source-
Source to be applied on the subscription and used to pay future invoices. Can be a card, a token or a gateway request
options-
Hashof options
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 |
# File 'lib/processout/subscription.rb', line 610 def apply_source(source, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "" data = { "source" => source } response = Response.new(request.put(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#cancel(cancellation_reason, options = {}) ⇒ Object
Cancel a subscription. The reason may be provided as well. Params:
cancellation_reason-
Cancellation reason
options-
Hashof options
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/processout/subscription.rb', line 635 def cancel(cancellation_reason, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "" data = { "cancellation_reason" => cancellation_reason } response = Response.new(request.delete(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#cancel_at_date(cancel_at, cancellation_reason, options = {}) ⇒ Object
Schedule the cancellation of the subscription. The reason may be provided as well. Params:
cancel_at-
Cancellation date, in the form of a string
cancellation_reason-
Cancellation reason
options-
Hashof options
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 |
# File 'lib/processout/subscription.rb', line 661 def cancel_at_date(cancel_at, cancellation_reason, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "" data = { "cancel_at" => cancel_at, "cancellation_reason" => cancellation_reason } response = Response.new(request.delete(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#create(customer_id, options = {}) ⇒ Object
Create a new subscription for the given customer. Params:
customer_id-
ID of the customer
options-
Hashof options
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'lib/processout/subscription.rb', line 461 def create(customer_id, = {}) request = Request.new(@client) path = "/subscriptions" data = { "cancel_at" => @cancel_at, "name" => @name, "amount" => @amount, "currency" => @currency, "metadata" => , "interval" => @interval, "trial_end_at" => @trial_end_at, "return_url" => @return_url, "cancel_url" => @cancel_url, "customer_id" => customer_id } response = Response.new(request.post(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#create_from_plan(customer_id, plan_id, options = {}) ⇒ Object
Create a new subscription for the customer from the given plan ID. Params:
customer_id-
ID of the customer
plan_id-
ID of the plan
options-
Hashof options
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 |
# File 'lib/processout/subscription.rb', line 496 def create_from_plan(customer_id, plan_id, = {}) request = Request.new(@client) path = "/subscriptions" data = { "cancel_at" => @cancel_at, "name" => @name, "amount" => @amount, "currency" => @currency, "metadata" => , "interval" => @interval, "trial_end_at" => @trial_end_at, "return_url" => @return_url, "cancel_url" => @cancel_url, "customer_id" => customer_id, "plan_id" => plan_id } response = Response.new(request.post(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#fetch_customer(options = {}) ⇒ Object
Get the customer owning the subscription. Params:
options-
Hashof options
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
# File 'lib/processout/subscription.rb', line 283 def fetch_customer( = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "/customers" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body["customer"] customer = Customer.new(@client) return_values.push(customer.fill_with_data(body)) return_values[0] end |
#fetch_discounts(options = {}) ⇒ Object
Get the discounts applied to the subscription. Params:
options-
Hashof options
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/processout/subscription.rb', line 305 def fetch_discounts( = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "/discounts" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new a = Array.new body = response.body for v in body['discounts'] tmp = Discount.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end |
#fetch_transactions(options = {}) ⇒ Object
Get the subscriptions past transactions. Params:
options-
Hashof options
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/processout/subscription.rb', line 404 def fetch_transactions( = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "/transactions" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new a = Array.new body = response.body for v in body['transactions'] tmp = Transaction.new(@client) tmp.fill_with_data(v) a.push(tmp) end return_values.push(a) return_values[0] end |
#fill_with_data(data) ⇒ Object
Fills the object with data coming from the API Params:
data-
Hashof data coming from the API
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
# File 'lib/processout/subscription.rb', line 203 def fill_with_data(data) if data.include? "id" self.id = data["id"] end if data.include? "project" self.project = data["project"] end if data.include? "plan" self.plan = data["plan"] end if data.include? "customer" self.customer = data["customer"] end if data.include? "token" self.token = data["token"] end if data.include? "url" self.url = data["url"] end if data.include? "name" self.name = data["name"] end if data.include? "amount" self.amount = data["amount"] end if data.include? "currency" self.currency = data["currency"] end if data.include? "metadata" self. = data["metadata"] end if data.include? "interval" self.interval = data["interval"] end if data.include? "trial_end_at" self.trial_end_at = data["trial_end_at"] end if data.include? "activated" self.activated = data["activated"] end if data.include? "active" self.active = data["active"] end if data.include? "canceled" self.canceled = data["canceled"] end if data.include? "cancellation_reason" self.cancellation_reason = data["cancellation_reason"] end if data.include? "pending_cancellation" self.pending_cancellation = data["pending_cancellation"] end if data.include? "cancel_at" self.cancel_at = data["cancel_at"] end if data.include? "return_url" self.return_url = data["return_url"] end if data.include? "cancel_url" self.cancel_url = data["cancel_url"] end if data.include? "sandbox" self.sandbox = data["sandbox"] end if data.include? "created_at" self.created_at = data["created_at"] end if data.include? "activated_at" self.activated_at = data["activated_at"] end if data.include? "iterate_at" self.iterate_at = data["iterate_at"] end self end |
#find(subscription_id, options = {}) ⇒ Object
Find a subscription by its ID. Params:
subscription_id-
ID of the subscription
options-
Hashof options
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 |
# File 'lib/processout/subscription.rb', line 531 def find(subscription_id, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(subscription_id) + "" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body["subscription"] obj = Subscription.new(@client) return_values.push(obj.fill_with_data(body)) return_values[0] end |
#find_discount(discount_id, options = {}) ⇒ Object
Find a subscription’s discount by its ID. Params:
discount_id-
ID of the discount
options-
Hashof options
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'lib/processout/subscription.rb', line 357 def find_discount(discount_id, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + "" data = { } response = Response.new(request.get(path, data, )) return_values = Array.new body = response.body body = body["discount"] discount = Discount.new(@client) return_values.push(discount.fill_with_data(body)) return_values[0] end |
#new(data = {}) ⇒ Object
Create a new Subscription using the current client
196 197 198 |
# File 'lib/processout/subscription.rb', line 196 def new(data = {}) Subscription.new(@client, data) end |
#remove_discount(discount_id, options = {}) ⇒ Object
Remove a discount applied to a subscription. Params:
discount_id-
ID of the discount or coupon to be removed from the subscription
options-
Hashof options
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/processout/subscription.rb', line 380 def remove_discount(discount_id, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "/discounts/" + CGI.escape(discount_id) + "" data = { } response = Response.new(request.delete(path, data, )) return_values = Array.new body = response.body body = body["discount"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#update(prorate, options = {}) ⇒ Object
Update the subscription. Params:
prorate-
Define if proration should be done when updating the plan
options-
Hashof options
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'lib/processout/subscription.rb', line 557 def update(prorate, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "" data = { "trial_end_at" => @trial_end_at, "prorate" => prorate } response = Response.new(request.put(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |
#update_plan(plan_id, prorate, options = {}) ⇒ Object
Update the subscription’s plan. Params:
plan_id-
ID of the new plan to be applied on the subscription
prorate-
Define if proration should be done when updating the plan
options-
Hashof options
584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/processout/subscription.rb', line 584 def update_plan(plan_id, prorate, = {}) request = Request.new(@client) path = "/subscriptions/" + CGI.escape(@id) + "" data = { "plan_id" => plan_id, "prorate" => prorate } response = Response.new(request.put(path, data, )) return_values = Array.new body = response.body body = body["subscription"] return_values.push(self.fill_with_data(body)) return_values[0] end |