Class: Hippo::API::Handlers::Subscription

Inherits:
ControllerBase show all
Defined in:
lib/hippo/api/handlers/subscription.rb

Instance Attribute Summary

Attributes inherited from ControllerBase

#data, #model, #params

Instance Method Summary collapse

Methods inherited from ControllerBase

#initialize

Methods included from FormattedReply

#json_status_str, #record_active_record_errors, #records_for_reply, #std_api_reply

Constructor Details

This class inherits a constructor from Hippo::API::ControllerBase

Instance Method Details

#destroyObject


28
29
30
31
32
33
34
35
36
# File 'lib/hippo/api/handlers/subscription.rb', line 28

def destroy
    tenant = Hippo::Tenant.current
    if tenant.subscription_id != params['id'].to_i
        return std_api_reply(:destroy, {}, success: false)
    end
    success = Hippo::Payments.cancel_subscription(tenant)
    tenant.save! if success
    std_api_reply(:retrieve, tenant.subscription, success: success)
end

#showObject


5
6
7
8
9
10
11
12
# File 'lib/hippo/api/handlers/subscription.rb', line 5

def show
    plan = Hippo::Subscription
               .find(params['id'])
               .as_json.merge(
                   authorization: Hippo::Payments.payment_authorization
               )
    std_api_reply(:retrieve, plan, success: true)
end

#updateObject


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hippo/api/handlers/subscription.rb', line 14

def update
    tenant = Hippo::Tenant.current
    subscription = Hippo::Subscription.find(data['id'])
    Hippo::Payments.set_tenant_payment_method(
        tenant, subscription, data['nonce']
    )
    success = subscription.errors.none?
    if success
        tenant.subscription = subscription
        tenant.save!
    end
    std_api_reply(:retrieve, subscription, success: success)
end