Sha256: 6e044c1451982314c88428de51166075724e0998bd6e5766d87736576f26b492

Contents?: true

Size: 825 Bytes

Versions: 3

Compression:

Stored size: 825 Bytes

Contents

require 'uri'

module Voucherify
  module Service
    class Redemptions
      attr_reader :client

      def initialize(client)
        @client = client
      end

      def redeem(code, params = {})
        @client.post("/vouchers/#{URI.encode(code)}/redemption", params.to_json)
      end

      def list(query = {})
        @client.get('/redemptions', query)
      end

      def get_for_voucher(code)
        @client.get("/vouchers/#{URI.encode(code)}/redemption")
      end

      def rollback(redemption_id, payload = {})
        reason = payload['reason'] || payload[:reason]
        params = reason ? {:reason => reason} : {}
        payload.delete 'reason'
        payload.delete :reason
        @client.post("/redemptions/#{URI.encode(redemption_id)}/rollback", payload.to_json, params)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
voucherify-1.3.0 lib/voucherify/service/redemptions.rb
voucherify-1.2.0 lib/voucherify/service/redemptions.rb
voucherify-1.1.0 lib/voucherify/service/redemptions.rb