0.0
No release in over a year
PaymobAccept is a Ruby gem created by OneOrder tech team for integrating Paymob payment solutions with your Ruby application.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

Paymob Accept

paymob_accept is a Ruby gem created by OneOrder for integrating Paymob payment solutions with your Ruby application.

Installation

Add this line to your appliciation's Gemfile:

gem 'paymob_accept'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install paymob_accept

Usage

Configuration

Configure the gem with your configuration

PaymobAccept.configure do |config|
    config.api_key = "######"
    config.hmac_key = "######"
    config.online_integration_id = "######"
    config.kiosk_integration_id = "######"
    config.cash_integration_id = "######"
    config.wallet_integration_id = "######"
    config.auth_integration_id = "######"
    config.moto_integration_id = "######"
end

Optionally, any configuration parameters mentioned above could be passed to the constructor when initializing the payment service.

💡 You can get your API_KEY from Settings -> Account info -> API Key in your Paymob portal.

For reference on the internals & specifics of Paymob, please head to their official documentation here

Creating a charge:

  1. Initialize your payment service

    service = PaymobAccept::Api::Pay.new(api_key: api_key, online_integration_id: "12345678")
  2. Prepare your customer data using the following schemas (All fields are required):

      customer_data = {name:  "test",  email:  "test@test.com",  phone_number:  "01000000000"}
      billing_address_data = {address_line1:  "10 street name", address_line2: "apt x. floor x",  region: "region", city: "Cairo", country: "EG"}
  3. Create a charge:

    service.charge(customer: customer_data, address: billing_address_data, method: :online, iframe_id: 'xxxxx', amount_cents: 1000)

Note. All integration id methods are public and could so it could be easily used to set an integration as:

service.online_integration_id = "123"

Alternatively, you can you create a charge step by step (Not recommended):

  1. Authentication request

    token = service.get_auth_token
  2. Create order

    service.create_order(auth_token: token, amount_cents:  1000,  amount_currency:  'EGP', items:  [])
    • Items are optional

      items  =  [{
          "name":  "xxxxxxx-1",
          "amount_cents": "5000",
          "description": "Smart Watch",
          "quantity": "10"
      }]
  3. Create payment key

    service.generate_payment_intent(customer: customer, address: address, integration_id: "xxxxx", amount_cents: amount_cents, amount_currency: "EGP", iframe_id: "xxxxxx", order_id: "xxxxxx")

Supported payment methods

The :method key in the charge method could be one of the following:

  • :online => 3D Secure payments with external redirection
  • :auth => Auth/Capture payments
  • :kiosk => Aman/Masary kiosk network
  • :cash => Cash on delivery
  • :wallet => Vodafone cash
  • :moto => Paying with a saved car token

Please refer to the official Paymob documentation for in-depth explanation about each payment method.

The return value of the charge method in general is the response of Paymob's server which varies according to the payment method except in :online. In an :online payment if an iframe_id is provided, the return value is an iFrame URL with an embedded payment token. If the iframe_id is not provided, only the payment token and order_id is returned

Paying with a saved card token

 def pay_moto(customer:, address:, cc_token:, amount_cents:, amount_currency:)
  • To pre-fill an iFrame with a customer card data or process a MOTO charge, make sure to pass the cc_token key in addition to the fields mentioned above.

Dealing with charges

  • Initialize your Charge service

    service = PaymobAccept::Api::Charge.new
  • Retrieve transaction: service.charge(transaction_id: transaction_id)

  • Refund transaction: service.refund!(transaction_id: transaction_id, amount_cents: amount_cents)

  • Void a transaction: service.void!(transaction_id: transaction_id)

  • Capture an auth transaction: service.capture!(transaction_id: transaction_id, amount_cents: amount_cents)

HMAC validation

PaymobAccept::Hmac.validate(paymob_response: , hmac_key:)

hmac_key can be either passed once to the configuration block, otherwise, it must be passed to the validate function.

Roadmap

  • HMAC validation

Contributing

Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

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

Code of Conduct

Everyone interacting in the PaymobAccept project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.