<commit_before># ArrowPayments

Ruby wrapper for Arrow Payments gateway

**Under Development**

## Installation

In your Gemfile add a line:

```
gem 'arrow_payments', :github => 'sosedoff/arrow_payments'
```

## Configuration

To configure gateway globally, add an initializer with the following:

```ruby
ArrowPayments::Configuration.api_key = 'foo'
ArrowPayments::Configuration.mode = 'production'
ArrowPayments::Configuration.merchant_id = '1231231'
```

Another way is to configure on the instance level:

```ruby
client = ArrowPayments::Client.new(
  :api_key     => 'foo', 
  :mode        => 'production',
  :merchant_id => '123451',
  :debug       => true
)
```

A set of helper methods:

```ruby
client.production? # => true
client.sandbox?    # => false
client.debug?      # => true
```

## Usage

Check the **API reference** section for objects details. 

Initialize a new client:

```ruby
client = ArrowPayments::Client.new(
  :api_key     => 'foo',
  :mode        => 'sandbox',
  :merchant_id => '12345'
)
```

### Customers

```ruby
# Get all customers. 
# Does not include recurring billings and payment methods.
client.customers # => [Customer, ...]

# Get customer details. 
# Returns nil if not found
client.customer('12345')

# Create a new customer. 
# Raises ArrowPayments::Error if unable to create.
customer = client.create_customer(
  :name => '<NAME>',
  :contact => '<NAME>',
  :code => 'JOHN',
  :email => '<EMAIL>',
  :phone => '(123) 123-12-12'
)

# Update an existing customer
customer = client.customer('12345')
customer.name = '<NAME>'
client.update_customer(customer) # => true

# Delete an existing customer
client.delete_customer('12345') # => true
```

### Payment Methods

Example: Add a new payment method to an existing customer

```ruby
client_id = '12345'

# Initialize a new billing address instance
address = ArrowPayments::Address.new(
  :address  => 'Some Street',
  :address2 => 'Apt 1',
  :city     => 'Chicago',
  :state    => 'IL',
  :zip      => '60657',
  :phone    => '123123123'
)

# Initialize a new payment method instance
cc = ArrowPayments::PaymentMethod.new(
  :first_name       => 'John',
  :last_name        => 'Doe',
  :number           => '4111111111111111',
  :security_code    => '123',
  :expiration_month => 12,
  :expiration_year  => 14
)

# Step 1: Provide payment method customer and billing address
url = client.start_payment_method(customer_id, address)

# Step 2: Add credit card information
token = client.setup_payment_method(url, cc)

# Step 3: Finalize payment method creation
cc = client.complete_payment_methodtoken)

# Delete an existing payment method
client.delete_payment_method('123456') # => true
```

You can also create a payment method using a wrapper method:

```
address = ArrowPayments::Address.new( ... data ... )<commit_msg>Readme update [ci-skip]<commit_after># ArrowPayments

Ruby wrapper for Arrow Payments gateway

**Under Development**

## Installation

In your Gemfile add a line:

```
gem 'arrow_payments', :github => 'sosedoff/arrow_payments'
```

## Configuration

To configure gateway globally, add an initializer with the following:

```ruby
ArrowPayments::Configuration.api_key = 'foo'
ArrowPayments::Configuration.mode = 'production'
ArrowPayments::Configuration.merchant_id = '1231231'
```

Another way is to configure on the instance level:

```ruby
client = ArrowPayments::Client.new(
  :api_key     => 'foo', 
  :mode        => 'production',
  :merchant_id => '123451',
  :debug       => true
)
```

A set of helper methods:

```ruby
client.production? # => true
client.sandbox?    # => false
client.debug?      # => true
```

## Usage

Check the **API reference** section for objects details. 

Initialize a new client:

```ruby
client = ArrowPayments::Client.new(
  :api_key     => 'foo',
  :mode        => 'sandbox',
  :merchant_id => '12345'
)
```

### Customers

```ruby
# Get all customers. 
# Does not include recurring billings and payment methods.
client.customers # => [Customer, ...]

# Get customer details. 
# Returns nil if not found
client.customer('12345')

# Create a new customer. 
# Raises ArrowPayments::Error if unable to create.
customer = client.create_customer(
  :name => '<NAME>',
  :contact => '<NAME>',
  :code => 'JOHN',
  :email => '<EMAIL>',
  :phone => '(123) 123-12-12'
)

# Update an existing customer
customer = client.customer('12345')
customer.name = '<NAME>'
client.update_customer(customer) # => true

# Delete an existing customer
client.delete_customer('12345') # => true
```

### Payment Methods

Example: Add a new payment method to an existing customer

```ruby
client_id = '12345'

# Initialize a new billing address instance
address = ArrowPayments::Address.new(
  :address  => 'Some Street',
  :address2 => 'Apt 1',
  :city     => 'Chicago',
  :state    => 'IL',
  :zip      => '60657',
  :phone    => '123123123'
)

# Initialize a new payment method instance
cc = ArrowPayments::PaymentMethod.new(
  :first_name       => 'John',
  :last_name        => 'Doe',
  :number           => '4111111111111111',
  :security_code    => '123',
  :expiration_month => 12,
  :expiration_year  => 14
)

# Step 1: Provide payment method customer and billing address
url = client.start_payment_method(customer_id, address)

# Step 2: Add credit card information
token = client.setup_payment_method(url, cc)

# Step 3: Finalize payment method creation
cc = client.complete_payment_methodtoken)

# Delete an existing payment method
client.delete_payment_method('123456') # => true
```

You can also create a payment method using a wrapper method:

```ruby
address = ArrowPayments::Address.new( ... data ... )
{'fraction_non_alphanumeric': 0.1393907190931633, 'fraction_numerical': 0.03400637619553666, 'mean_word_length': 4.041964285714286, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '276131', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1741, 'n_words': 529}