<commit_before>[![Code Climate](https://codeclimate.com/repos/524eb044f3ea00329815dff1/badges/885c2d52f25c02295344/gpa.png)](https://codeclimate.com/repos/524eb044f3ea00329815dff1/feed)

# OpenPayU Ruby

The OpenPayU Ruby library provides integration access to the PayU Gateway API ver. 2.

## Installation

Add this line to your application's Gemfile:

    gem 'openpayu'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install openpayu

##Configure Gem
  To configure OpenPayU environment add a file to config/initializers/openpayu.rb containing:

    OpenPayU::Configuration.configure do |config|
        config.merchant_pos_id  = '145227'
        config.signature_key    = '<KEY>'
        config.algorithm        = 'MD5' # MD5, SHA-1, SHA-256
        config.service_domain   = 'payu.com'
        config.protocol         = 'https'
        config.data_format      = 'json' # json, xml
        config.env              = 'secure'
        config.order_url        = 'http://localhost/order'
        config.notify_url       = 'http://localhost/notify'
        config.continue_url     = 'http://localhost/success'
    end

  Or by providing a path to YAML file

    OpenPayU::Configuration.configure File.join(Rails.root, 'config/openpayu.yml')

  Structure of YAML file:

    development:
      merchant_pos_id: '145227'
      signature_key: <KEY>
      algorithm: MD5 # MD5, SHA-1, SHA-256
      service_domain: payu.com
      protocol: https
      data_format: json # json, xml
      env: secure
      order_url: http://localhost/order
      notify_url: http://localhost/notify
      continue_url: http://localhost/success
    production:
      merchant_pos_id: '145227'
      signature_key: <KEY>
      algorithm: MD5 # MD5, SHA-1, SHA-256
      service_domain: payu.com
      protocol: https
      data_format: json # json, xml
      env: secure
      order_url: http://localhost/order
      notify_url: http://localhost/notify
      continue_url: http://localhost/success

##Usage

###Creating Transparent order
  For more information about order please refer to: http://developers.payu.com/pl/restapi.html#payusdk_creating_new_order_api
  To create an order you must provide a Hash with order:

    order = {
      merchant_pos_id: "145227",
      customer_ip: "127.0.0.1", # You can user request.remote_ip in your controller
      ext_order_id: 1342, #Order id in your system
      order_url: "http://localhost/",
      description: "New order",
      currency_code: "PLN",
      total_amount: 10000,
      notify_url: "http://localhost/",
      continue_url: "http://localhost/",
      buyer: {
        email: '<EMAIL>',
        phone: '123123123',
        first_name: 'Jan',
        last_name: 'Kowalski',
        language: 'pl_PL',
        delivery: {
          street: 'street',<commit_msg>added link to docs<commit_after>[![Code Climate](https://codeclimate.com/repos/524eb044f3ea00329815dff1/badges/885c2d52f25c02295344/gpa.png)](https://codeclimate.com/repos/524eb044f3ea00329815dff1/feed)

# OpenPayU Ruby

The OpenPayU Ruby library provides integration access to the PayU Gateway API ver. 2.

## Installation

Add this line to your application's Gemfile:

    gem 'openpayu'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install openpayu

##Configure Gem
  To configure OpenPayU environment add a file to config/initializers/openpayu.rb containing:

    OpenPayU::Configuration.configure do |config|
        config.merchant_pos_id  = '145227'
        config.signature_key    = '<KEY>'
        config.algorithm        = 'MD5' # MD5, SHA-1, SHA-256
        config.service_domain   = 'payu.com'
        config.protocol         = 'https'
        config.data_format      = 'json' # json, xml
        config.env              = 'secure'
        config.order_url        = 'http://localhost/order'
        config.notify_url       = 'http://localhost/notify'
        config.continue_url     = 'http://localhost/success'
    end

  Or by providing a path to YAML file

    OpenPayU::Configuration.configure File.join(Rails.root, 'config/openpayu.yml')

  Structure of YAML file:

    development:
      merchant_pos_id: '145227'
      signature_key: <KEY>
      algorithm: MD5 # MD5, SHA-1, SHA-256
      service_domain: payu.com
      protocol: https
      data_format: json # json, xml
      env: secure
      order_url: http://localhost/order
      notify_url: http://localhost/notify
      continue_url: http://localhost/success
    production:
      merchant_pos_id: '145227'
      signature_key: 13a980d4f851f3d9a1cfc792fb1f5e50
      algorithm: MD5 # MD5, SHA-1, SHA-256
      service_domain: payu.com
      protocol: https
      data_format: json # json, xml
      env: secure
      order_url: http://localhost/order
      notify_url: http://localhost/notify
      continue_url: http://localhost/success

##Usage

###Creating Transparent order
  For more information about order please refer to: http://developers.payu.com/pl/restapi.html#payusdk_creating_new_order_api .
  To create an order you must provide a Hash with order:

    order = {
      merchant_pos_id: "145227",
      customer_ip: "127.0.0.1", # You can user request.remote_ip in your controller
      ext_order_id: 1342, #Order id in your system
      order_url: "http://localhost/",
      description: "New order",
      currency_code: "PLN",
      total_amount: 10000,
      notify_url: "http://localhost/",
      continue_url: "http://localhost/",
      buyer: {
        email: '<EMAIL>',
        phone: '123123123',
        first_name: 'Jan',
        last_name: 'Kowalski',
        language: 'pl_PL',
        delivery: {
          street: 'street',
{'fraction_non_alphanumeric': 0.10408594575554773, 'fraction_numerical': 0.043853469531525184, 'mean_word_length': 2.6638709677419357, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2692147', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1763, 'n_words': 438}