Sha256: 01c36d5d04e2fa980e462ba87d3a79c95c3d5d04924ef15c049304b069acc91a

Contents?: true

Size: 1.75 KB

Versions: 17

Compression:

Stored size: 1.75 KB

Contents

require 'voucherify/utils'

base_price = 20.00

puts 'base price: ' + base_price.to_s

puts '===== amount discount ====='
amount_voucher = {
    discount: {
        amount_off: 1000, # 10.0
        type: 'AMOUNT'
    }
}
puts 'discount:             ' + Voucherify::Utils.calculate_discount(base_price, amount_voucher).to_s
puts 'price after discount: ' + Voucherify::Utils.calculate_price(base_price, amount_voucher).to_s
puts


puts '===== percent discount ===='

percent_discount_voucher = {
    discount: {
        percent_off: 20,
        type: 'PERCENT'
    }
}

puts 'discount:             ' + Voucherify::Utils.calculate_discount(base_price, percent_discount_voucher).to_s
puts 'price after discount: ' + Voucherify::Utils.calculate_price(base_price, percent_discount_voucher).to_s
puts


puts '===== unit discount ======='

unit_discount_voucher = {
    discount: {
        unit_off: 2,
        type: 'UNIT'
    }
}

puts 'discount:             ' + Voucherify::Utils.calculate_discount(base_price, unit_discount_voucher, 5).to_s
puts 'price after discount: ' + Voucherify::Utils.calculate_price(base_price, unit_discount_voucher, 5).to_s
puts


puts '===== gift voucher ========'

gift_voucher = {
    gift: {
        amount: 1000,
        balance: 500
    }
}

puts 'discount:             ' + Voucherify::Utils.calculate_discount(base_price, gift_voucher).to_s
puts 'price after discount: ' + Voucherify::Utils.calculate_price(base_price, gift_voucher).to_s
puts

puts '===== gift voucher 2 ======'

gift_voucher2 = {
    gift: {
        amount: 10000,
        balance: 5000
    }
}

puts 'discount:             ' + Voucherify::Utils.calculate_discount(base_price, gift_voucher2).to_s
puts 'price after discount: ' + Voucherify::Utils.calculate_price(base_price, gift_voucher2).to_s
puts

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
voucherify-4.1.0 examples/utils.rb
voucherify-4.0.0 examples/utils.rb
voucherify-3.0.0 examples/utils.rb
voucherify-2.4.0 examples/utils.rb
voucherify-2.3.0 examples/utils.rb
voucherify-2.2.0 examples/utils.rb
voucherify-2.1.1 examples/utils.rb
voucherify-2.1.0 examples/utils.rb
voucherify-2.0.0 examples/utils.rb
voucherify-1.6.1 examples/utils.rb
voucherify-1.6.0 examples/utils.rb
voucherify-1.5.0 examples/utils.rb
voucherify-1.4.0 examples/utils.rb
voucherify-1.3.0 examples/utils.rb
voucherify-1.2.0 examples/utils.rb
voucherify-1.1.0 examples/utils.rb
voucherify-1.0.0 examples/utils.rb