Coder Social home page Coder Social logo

besepa-ruby's Introduction

Besepa::Ruby

A Ruby gem to Besepa.com's API.

Installation

Add this line to your application's Gemfile:

gem 'besepa'

And then execute:

$ bundle

Or install it yourself as:

$ gem install besepa

Documentation

http://apidocs.besepa.com

Configuration

Besepa.configure do |config|
  config.api_key = API_KEY 
  config.endpoint = API_END_POINT
end

By default, this gem points to Besepa's sandbox (https://sandbox.besepa.com). If you want to point to Besepa's production environment, use https://api.besepa.com as endpoint.

Remeber that API_KEY changes from one environment to the other.

Usage

Add new customer

Besepa::Customer.new(id: customer_id)
#=> <Besepa::Customer:0x0000 @id=nil, @name=nil, @taxid=nil, @reference=nil, @contact_name=nil, @contact_email=nil, @contact_phone=nil, @contact_language=nil, @address_street=nil, @address_city=nil, @address_postalcode=nil, @address_state=nil, @address_country=nil, @status=nil, @created_at=nil>

Create empty object but do not save it.

or

Besepa::Customer.create(name: 'name')
#=> <Besepa::Customer:...,@name="name",...>

Get all customers

Besepa::Customer.all
#=>=> [#<Besepa::Customer:...>, #<Besepa::Customer:...>]

Get one customer's information

Besepa::Customer.find( customer_id  )
#=> #<Besepa::Customer:...,@id= customer_id>

Update customer

c = Besepa::Customer.find( customer_id  )
#=>#<Besepa::Customer:...>
c.name = 'New name'
#=> "New name"
c.save
#=>=> #<Besepa::Customer:..., @name= "New name",...>

Remove customer

c = Besepa::Customer.find( customer_id  )
#=>#<Besepa::Customer:...>
c.destroy #customer's state is change to 'REMOVED'
#=> #<Besepa::Customer:..., @status="REMOVED",...>

Note all subscriptions, upcoming debits and mandates for this customer will be cancelled

Get customer's bank accounts

Besepa::Customer.find( customer_id  ).bank_accounts
# => [#<Besepa::BankAccount:..., #<Besepa::BankAccount:...>]

The result is a array of Besepa::BankAccount

In case you don't have a Customer yet, just create one Customer object with it's id.

Besepa::Customer.new( id: customer_id  ).bank_accounts

Add a bank account to a customer

Besepa::Customer.new( id: customer_id  ).add_bank_account(iban, bic, bank_name)
# => #<Besepa::BankAccount:...>

bank_name is optional.

Update bank account

b = Besepa::Customer.find(customer_id).bank_accounts.detect{|b|  b.id == bank_account_id }
# => #<Besepa::BankAccount:...>
b.replace(iban, bic, bank_name)
#=> #<Besepa::BankAccount:... >

bank_name is optional. Other possible arguments are signature_type, phone_number and redirect_after_signature

Get customer's debits

Besepa::Customer.new( id: customer_id  ).debits
#=>=> [#<Besepa::Debit:...>, #<Besepa::Debit:...>]

Create a debit for a customer

Besepa::Customer.new(id: customer_id  ).add_debit(bank_account_id, reference, description, amount, collect_at, creditor_account_id, metadata)
#=> #<Besepa::Debit:...>

Amount is with two decimals, without separation character (1000 == 10.00) Metadata can be a hash that we will store associated to this debit. creditor_account_id is optional, if none passed, we will use account's default one. The bank_account status should be 'ACTIVE'

Get customer's subscriptions

Besepa::Customer.new( id: customer_id  ).subscriptions
#=> [#<Besepa::Subscription:...>, #<Besepa::Subscription:...>]>

Add customer'subscription

Besepa::Customer.find(customer_id).add_subscription(starts_at, product_code, bank_account_id)
#=> #<Besepa::Subscription:...>

Remmember that the bank account status should be 'ACTIVE'

Get customer's groups List of groups this customer belongs to

Besepa::Customer.find(customer_id).groups
#=>[#<Besepa::Group:...>, #<Besepa::Group:...>]

Add customer to group

Besepa::Customer.find(customer_id).add_to_group(group_id)
# => true

Remove customer from the group

Besepa::Customer.find(customer_id).remove_from_group(group_id)
# => true

Supported Ruby Versions

Right now, this gem has been tested with Ruby 2 only. More coming.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Copyright

Copyright (c) 2015 Besepa Technologies S.L.. See LICENSE for details.

besepa-ruby's People

Contributors

ceritium avatar danilat avatar dgilperez avatar mayoral avatar molpe avatar oinak avatar ro-fdm avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

besepa-ruby's Issues

CHANGELOG

It's a nice thing to have :-) Could you consider adding one?

¿Qué hago mal?

No se guarda el cliente (DEVELOPMENT)

def create

@hotel = @hotel.update(hotel_params)

  @hotel.user = current_user
  @hotel.publish = false
  @customer = Besepa::Customer.create(@hotel.account.name)
  iban = @hotel.account.iban
  bic = @hotel.account.bic
  bank_name = @hotel.account.bank
  mandate_options = {
    scheme: "CORE", #o b2b
    signature_type: 'checkbox', # o sms. Si es SMS, añadir el teléfono en phone_number o se lo pedimos
    type: "RECURRENT",
    redirect_after_signature: "https://waitinglist.es/hoteles?mandato=firmado"
  }
ba = @customer.add_bank_account(iban, bic, bank_name, mandate_options)
@hotel.ba_url = ba.url
  respond_to do |format|
    if @hotel.save(validate: false)
# resto...

initializers/besepa.rb:


Besepa.configure do |config|
  config.api_key = 'mi API key' 
  config.endpoint = 'https://sandbox.besepa.com)'
end

Validation errors

Hi!

Is there any way to get information about validation errors from the API? Right now, I'm just receiving a 422 error when trying to add a debit to a customer, with no further explanation:

Besepa::Customer.find(id).add_debit("XXXXXXX", "XXXXXX", "My description", 10000, "2014-05-10", nil, nil)
# => Besepa::Errors::InvalidResourceError: (Status 422) invalid_resource (El recurso no se puedo guardar porque falló alguna de las validaciones)

Both customer and bank_account exist.

Thanks!

default_endpoint in README does not correspond to the actual code

The README says

By default, this gem points to Besepa's sandbox (https://sandbox.besepa.com). If you want to point to Besepa's production environment, use https://api.besepa.com as endpoint.

but according to
https://github.com/besepa/besepa-ruby/blob/master/lib/besepa/utils/config.rb#L12

DEFAULT_ENDPOINT = 'http://app.besepa.com'

So either the README or config.rb should be updated 😉

Also note that the code says app.besepa.com and the readme says api.besepa.com - I don't know which one is the right one or if it doesn't matter 😃

Test de las funciones nuevas

alguien han subido funcionalidad nueva sin tests, estaría bien revisar la cobertura de test en general y mejorarla

Código sin tests:

puede que falte asimismo un release de los últimos cambios

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.