Sha256: c6f9ac50b9e426f3db00a6a093c8761067e198709192e25353ee55fe1c3b1fc0

Contents?: true

Size: 1.57 KB

Versions: 2

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

module OnlinePaymentPlatform
  class Client
    class Merchant
      attr_reader :uid, :features, :transactions

      extend Methods

      def initialize(opts = {})
        @features = opts
        @uid = @features['uid']
        @transactions = Transaction.new @uid
      end

      def update(opts = {})
        parent = self.class
        parent.assert_one_of!(opts, :notify_url, :return_url, :metadata, :status)
        response = parent.post parent.generate_uri(:merchants, uid), opts
        Merchant.new response
      end

      def delete
        update(status: :terminated)
      end

      def suspend
        update(status: :suspended)
      end

      def migrate(opts = {})
        parent = self.class
        parent.assert_required_keys!(opts, :coc_nr, :country)
        response = parent.post parent.generate_uri(:merchants, uid, :migrate), opts
        Merchant.new response
      end

      def self.find_or_create(opts = {})
        assert_required_keys!(opts, :country, :emailaddress, :notify_url, :phone)
        response = fetch(generate_uri(:merchants) + "?filter[0][name]=emailaddress&filter=[0][operand]=eq&filter[0][value]=#{opts[:emailaddress]}")

        byebug
      end

      def self.create(opts = {})
        assert_required_keys!(opts, :country, :emailaddress, :notify_url, :phone)
        Merchant.new post(generate_uri(:merchants), opts)
      end

      def self.find(uid)
        response = fetch generate_uri(:merchants, uid)
        Merchant.new response
      end
    end

    def self.merchants
      Merchant
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
online_payment_platform-0.0.3 lib/online_payment_platform/client/merchant.rb
online_payment_platform-0.0.2 lib/online_payment_platform/client/merchant.rb