Sha256: c1f3bb778dc9c516c0b820e50b25d5df20fe395b5b7bf2beb320e421543861dc

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module Paddle
  class Subscription < Object

    class << self

      def list(**params)
        response = Client.get_request("subscriptions", params: params)
        Collection.from_response(response, type: Subscription)
      end

      def retrieve(id:, extra: nil)
        params = extra ? {include: extra} : {}
        response = Client.get_request("subscriptions/#{id}", params: params)
        Subscription.new(response.body["data"])
      end

      def get_transaction(id:)
        response = Client.get_request("subscriptions/#{id}/update-payment-method-transaction")
        Transaction.new(response.body["data"])
      end

      def preview(id:, **params)
        response = Client.patch_request("subscriptions/#{id}/preview", body: params)
        Subscription.new(response.body["data"])
      end

      def update(id:, **params)
        response = Client.patch_request("subscriptions/#{id}", body: params)
        Subscription.new(response.body["data"])
      end

      def charge(id:, items:, effective_from:, **params)
        attrs = {items: items, effective_from: effective_from}
        response = Client.post_request("subscriptions/#{id}/charge", body: attrs.merge(params))
        Subscription.new(response.body["data"])
      end

      def pause(id:, **params)
        response = Client.post_request("subscriptions/#{id}/pause", body: params)
        Subscription.new(response.body["data"])
      end

      def resume(id:, effective_from:, **params)
        attrs = {effective_from: effective_from}
        response = Client.post_request("subscriptions/#{id}/resume", body: attrs.merge(params))
        Subscription.new(response.body["data"])
      end

      def cancel(id:, **params)
        response = Client.post_request("subscriptions/#{id}/cancel", body: params)
        Subscription.new(response.body["data"])
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
paddle-2.1.1 lib/paddle/models/subscription.rb