Giter VIP home page Giter VIP logo

payture-ewallet's Introduction

Payture::Ewallet

Build Status

Simple Ruby wrapper for Payture eWallet API.

Installation

Add this line to your application's Gemfile:

gem 'payture-ewallet'

And then execute:

$ bundle

Or install it yourself as:

$ gem install payture-ewallet

Usage

Create client

Required options are host, merchant_id, password and currency. You can get them from Payture tech support.

payture = Payture::Ewallet.client(
  host: 'sandbox.payture.com',
  merchant_id: 'TestMerchant',
  password: '12345',
  currency: 'RUB',
)

You can also specify optional settings:

payture = Payture::Ewallet.client(
  host: 'sandbox.payture.com',
  merchant_id: 'TestMerchant',
  password: '12345',
  currency: 'RUB',
  timeout: 10,
  open_timeout: 5,
  logger: Logger.new,
)

Init payment

response = payture.init(
  # required
  user_login: '[email protected]',
  user_password: '12345',
  user_ip: '192.168.0.1',
  order_id: '123',
  amount: Money.new(100_00, 'RUB'),
  # optional
  user_phone: '+79201234567',
  card_id: '123',
  template: 'custom_tpl',
  language: 'ru',
  return_url: 'https://myshop.com/order/123',
  cheque: {
    Positions: [...],
  },
)

response.success?
# => true
response.session_id
# => "36a02faf-ae1b-443b-8fcc-188614390a91"

If response has error:

response.error?
# => true
response.error_code
# => "DUPLICATE_ORDER_ID"

Build payment URL

session_id contains value from previous step.

payture.pay_url(session_id: '36a02faf-ae1b-443b-8fcc-188614390a91')
=> "https://sandbox.payture.com/vwapi/Pay?SessionId=36a02faf-ae1b-443b-8fcc-188614390a91"

You need to redirect user to this URL.

Charge

After the user has paid, you can charge money from card:

response = payture.charge(
  # required
  order_id: '123',
  # optional
  amount: Money.new(100_00, 'RUB'),
  cheque: {
    Positions: [...],
  },
)

response.success?
# => true
response.charged_amount
# => #<Money fractional:10000 currency:RUB>

Unblock

You also can unblock money if you don't need charge them:

response = payture.unblock(
  # required
  order_id: '123',
  amount: Money.new(100_00, 'RUB'),
)

response.success?
# => true
response.actual_amount
# => #<Money fractional:0 currency:RUB>

Refund

If money already charged, you can refund them:

response = payture.refund(
  # required
  order_id: '123',
  amount: Money.new(80_00, 'RUB'),
  # optional
  cheque: {
    Positions: [...],
  },
)

response.success?
# => true
response.actual_amount
# => #<Money fractional:2000 currency:RUB>

Payment status

For get actual payment status you can use method pay_status:

response = payture.pay_status(order_id: '123')

response.success?
# => true
response.status
# => "Authorized"
response.amount
# => #<Money fractional:10000 currency:RUB>
response.card_id
# => "..."
response.user_login
# => "[email protected]"

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/busfor/payture-ewallet. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

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.