Sha256: 20d6eeac1c80560f903ea2cd42d83a449b11f4ec688485a1e20c68665d1e5759

Contents?: true

Size: 569 Bytes

Versions: 4

Compression:

Stored size: 569 Bytes

Contents

module Tang
  class ApplyCustomerDiscount
    def self.call(customer, coupon)
      if customer.stripe_id.present?
        begin
          cu = Stripe::Customer.retrieve(customer.stripe_id)
          cu.coupon = coupon.stripe_id
          cu.save

          start = cu.discount.start.to_s
          start_timestamp = DateTime.strptime(start, '%s')
          customer.update(coupon: coupon, coupon_start: start_timestamp)
        rescue Stripe::StripeError => e
          customer.errors[:base] << e.message
        end
      end

      return customer
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
tang-0.2.0 app/services/tang/apply_customer_discount.rb
tang-0.1.0 app/services/tang/apply_customer_discount.rb
tang-0.0.9 app/services/tang/apply_customer_discount.rb
tang-0.0.8 app/services/tang/apply_customer_discount.rb