Code Monkey home page Code Monkey logo

paytm-merchant's Introduction

Paytm Merchant Gem Version

This is a ruby library(and not just rails gem) for PayTM Merchant transactions API. You can easily integrate you application to pay your users/winners by calling Paytm.new({amount: 110, phone: '7777777777'}).transfer

Installation

Add this line to your application's Gemfile:

gem 'paytm-merchant'

And then execute:

$ bundle

Or install it yourself as:

$ gem install paytm-merchant

Usage

To setup, first initialize the library with credentials.

require 'paytm/merchant'

Paytm.config do |paytm|
  # paytm.api_base_uri = 'Some Base URI' # Default is staging api URI fpr paytm
  paytm.merchant_guid = 'Paytm Merchant Guid'
  paytm.aes_key = 'Paytm AES Key'
  paytm.sales_wallet_id = 'Paytm Sales Wallet Id'
end

For Rails

$ rails generate paytm_setup

The above line will create a paytm.rb file initializes directory where you can update the credentials.

Funtionality

Create paytm object of Paytm class.

paytm_obj = Paytm.new(
  amount: 120,
  recipient: 'some user',
  phone: '7777777777',
  email: '[email protected]'
)

Transfer

paytm_obj.transfer         # Returns the HTTParty response object

You can specify different options for transfer

paytm_obj.transfer(
  request_type:         nil,                              # +nil+ for normal transfer request
  merchant_order_id:    'Unique id per transaction',      # Default order id is made using phone number and current timestamp
  sales_wallet_name:    'As per your paytm credentials',  # Leave blank if not known
  payee_sso_id:         'As per your paytm credentials',  # Leave blank if not known
  applied_to_new_users: 'Y',                              # 'Y' or 'N'; Whether to create paytm account for new phone no.
  amount:                150,
  currency_code:        'INR'                             # Currency code specified by Paytm. Default 'INR'
  metadata:             'Test Transaction',               # Extra details to be sent for transaction
  ip_address:           '127.0.0.1',                      # As you want
  verify:               true                              # true or false for SSL verification by OpenSSL for request
)

Response

{"type"=>nil,
 "requestGuid"=>nil,
 "orderId"=>"7777777777-1485612494",
 "status"=>"SUCCESS",
 "statusCode"=>"SUCCESS",
 "statusMessage"=>"SUCCESS",
 "response"=>{"walletSysTransactionId"=>"515571"},
 "metadata"=>""}

Check Transaction

paytm_obj.new.check_transaction_status_for('515571')      # First agrument is paytm wallet txn id recieved in txn response

You can specify different options

paytm_obj.new.check_transaction_status_for(
  '515571',                                       # This id is the id as per in +transaction_id_type+ option
  {
    transaction_id_type: :paytm_transaction_id,   # Possible values, :paytm_transaction_id, :merchant_order_id, :refund_reference_id. Default is :paytm_transaction_id
    transaction_type: 'salestouser',              # Possible values as per Paytm API

  }
)

Response

{
  "type"=>nil,
  "requestGuid"=>nil,
  "orderId"=>nil,
  "status"=>"SUCCESS",
  "statusCode"=>"SS_001",
  "statusMessage"=>"SUCCESS",
  "response"=>
    {"txnList"=>
      [{
        "txnGuid"=>"515323",
        "txnAmount"=>110,
        "status"=>1,
        "message"=>"SUCCESS",
        "txnErrorCode"=>nil,
        "ssoId"=>"11065108",
        "txnType"=>"SALES_TO_USER_CREDIT",
        "merchantOrderId"=>"7777777777-1485604732",
        "pgTxnId"=>"\"null\"",
        "pgRefundId"=>"\"null\"",
        "cashbackTxnId"=>nil,
        "isLimitPending"=>false
      }]
    },
  "metadata"=>nil
 }

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/schnmudgal/paytm-merchant. 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.

paytm-merchant's People

Contributors

schnmudgal avatar

Stargazers

 avatar

Watchers

 avatar

paytm-merchant's Issues

Request Details

Hi @schnmudgal how can I get the full request details after making the transfer.

Below is the code to make transfer

paytm = Paytm.new(amount: amount, phone: mobile_no, recipient: user.name, email: user.email) response = paytm.transfer( request_type: nil, merchant_order_id: Utils.payment_trans_id, sales_wallet_name: 'My Sub Wallet', payee_sso_id: '********', applied_to_new_users: 'N', amount: 10, currency_code: 'INR', metadata: 'Test Transaction', ip_address: '192.168.0.2', verify: true)

The Response
{"amount"=>10, "recipient"=>"Ishwar Verma", "phone"=>"809532****", "email"=>"ishwar.verma@******.com", "checksum"=>"A8nyVMRVxX6GQSG5vuGyHHZprfrwuIphtGMOqrVFiOmSu5jO+jG2n4pJrUF5VWwgUmJ8D0IbfCMS0kOkD2vPBTpD+hT9k7nxAITNyeRoBa8=", "response"=>"{\"type\":null,\"requestGuid\":null,\"orderId\":null,\"status\":null,\"statusCode\":\"GE_1043\",\"statusMessage\":\"Merchant does not exists\",\"response\":null,\"metadata\":null}"}

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.