Sha256: 1cbf74aa7c7000229b920e3411aa193ed2a1b8b71556a1e0e5fe6475d5101c87

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 KB

Contents

module Paddle
  module Classic
    class CouponsResource < Resource
      def list(product_id:)
        response = post_request("2.0/product/list_coupons", body: { product_id: product_id })
        Collection.from_response(response, type: Coupon)
      end

      def create(coupon_type:, discount_type:, discount_amount:, **params)
        attrs = { coupon_type: coupon_type, discount_type: discount_type, discount_amount: discount_amount }

        response = post_request("2.1/product/create_coupon", body: attrs.merge(params))

        coupons =  response.body["response"]["coupon_codes"]

        coupons.map { |c| Paddle::Coupon.new(code: c) }
      end

      def delete(coupon_code:, product_id:)
        attrs = { coupon_code: coupon_code, product_id: product_id }
        response = post_request("2.0/product/delete_coupon", body: attrs)
        true if response.success?
      end

      def update(**params)
        response = post_request("2.1/product/update_coupon", body: params)
        true if response.success?
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
paddle-2.7.0 lib/paddle/classic/resources/coupons.rb
paddle-2.6.0 lib/paddle/classic/resources/coupons.rb
paddle-2.5.2 lib/paddle/classic/resources/coupons.rb
paddle-2.5.1 lib/paddle/classic/resources/coupons.rb
paddle-2.5.0 lib/paddle/classic/resources/coupons.rb
paddle-2.4.1 lib/paddle/classic/resources/coupons.rb
paddle-2.4.0 lib/paddle/classic/resources/coupons.rb
paddle-2.3.0 lib/paddle/classic/resources/coupons.rb
paddle-2.2.1 lib/paddle/classic/resources/coupons.rb