Sha256: fcf5084ef14489780d86f132a4e7330ef8f2a0fdcde036aa5df9540ee704fe51

Contents?: true

Size: 1.18 KB

Versions: 8

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Ledgers
    module Stripe
      class Customer
        module Operations
          class Create < Stripe::Operation::Create
            class Contract < LedgerSync::Ledgers::Contract
              params do
                required(:external_id).maybe(:string)
                required(:ledger_id).value(:nil)
                required(:email).maybe(:string)
                required(:name).filled(:string)
                required(:phone_number).maybe(:string)
                optional(:subsidiary).maybe(:hash, Types::Reference)
              end
            end

            private

            def operate
              stripe_customer = ::Stripe::Customer.create(
                email: resource.email,
                metadata: {
                  external_id: resource.external_id
                },
                name: resource.name,
                phone: resource.phone_number
              )

              resource.ledger_id = stripe_customer.id

              success(
                resource: resource,
                response: stripe_customer
              )
            end
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
ledger_sync-1.6.0 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.4.4 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.4.2 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.4.1 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb
ledger_sync-1.4.0 lib/ledger_sync/ledgers/stripe/customer/operations/create.rb