项目作者: dsfx3d

项目描述 :
:moneybag: core python PayU Money Payment Gateway integration utilities
高级语言: Python
项目地址: git://github.com/dsfx3d/pay-me.git
创建时间: 2018-11-26T11:26:35Z
项目社区:https://github.com/dsfx3d/pay-me

开源协议:MIT License

下载


:moneybag: payme

payme is collection of utilities for PayUMoney redirection based payment gateway integration. It includes a hasher module to generate request hash when requesting payments and to check response hash recieved after payment transaction completion.

Installation

  1. pip install payme

Usage

  1. from payme.hashers import Hasher

Example

1. module hasher

This module contains the class required to generate hash while making payment request to payu gateway via redirection. Same class also contain method to check hash recieved from payu payment gateway after payment request is processed and gateway redirects to requestee.

  1. payu_key # merchant key from PayU Merchant Dashboard
  2. payu_salt # merchant salt from PayU Merchant Dashboard
  3. hasher = Hasher(payu_key, payu_salt)
  4. # data to be posted to PayU Gateway transaction request endpoint
  5. # required keys
  6. request_data = {
  7. 'txnid': 'unique_id',
  8. 'amount': 99,
  9. 'productinfo': 'this is a product',
  10. 'firstname': 'John',
  11. 'email': 'johnsnow@example.com'
  12. }
  13. # you may also include upto 10 optional user difined fields
  14. # example
  15. request_data.update({
  16. 'udf1': 'udf1',
  17. 'udf2': 'udf2',
  18. 'udf3': 'udf3',
  19. 'udf4': 'udf4',
  20. 'udf5': 'udf5',
  21. 'udf6': 'udf6',
  22. 'udf7': 'udf7',
  23. 'udf8': 'udf8',
  24. 'udf9': 'udf9',
  25. 'udf10': 'udf10',
  26. })
  27. # hash string to be posted along request_data
  28. request_hash = hasher.generate_hash(request_data)
  29. # post data recived on success url after PayU Gateway redirection
  30. response_data
  31. # true if data is valid else false
  32. hasher.check_hash(response_data)

2. api package

2.1 module inquiry

This module contains class for making requests to payu payment inquiry api

  1. PAYU_KEY # merchant key from payu dashboard
  2. PAYU_AUTH_HEADER # auth header from payu dashboard
  3. TXN_ID = '123xxx' # merchant txnid passed while making payment
  4. TXN_IDS = ('54xxx', '133xxx') # multiple merchant txnids
  5. inquiry_api = inquiry.InquiryApi()
  6. # returns status dict; check payu api reference for returned dict keys
  7. payment_status_dict = inquiry_api.check_merchant_txn_status(PAYU_AUTH_HEADER, PAYU_KEY, TXN_ID)
  8. # returns status dict; check payu api reference for returned dict keys
  9. multiple_payments_status_dict = inquiry_api.check_merchant_txn_status(PAYU_AUTH_HEADER, PAYU_KEY, TXN_IDS)
  10. # returns complete payment response details of transactions; check payu api reference for returned dict keys
  11. payment_res_dict = inquiry_api.get_payment_response(PAYU_AUTH_HEADER, PAYU_KEY, TXN_ID)
  12. multiple_payments_res_dict = inquiry_api.get_payment_response(PAYU_AUTH_HEADER, PAYU_KEY, TXN_IDS)

2.2 module refund

This module contains class for making requests to payu payment refund api

  1. PAYU_KEY # merchant key from payu dashboard
  2. PAYU_AUTH_HEADER # auth header from payu dashboard
  3. PAYMENT_ID # payu payment id
  4. REFUND_AMOUNT #
  5. refund_api = refund.RefundApi()
  6. # initiate refund process; check payu api reference for response dict keys
  7. response = refund_api.init_refund_payment(PAYU_AUTH_HEADER, PAYU_KEY, PAYMENT_ID, REFUND_AMOUNT)
  8. # if refund initiated
  9. refund_id = response.get('result')
  10. # get refund process details; check payu api reference for returned dict keys
  11. refund_api.get_refund_details_by_refund_id(PAYU_AUTH_HEADER, PAYU_KEY, refund_id)
  12. # or you can use
  13. refund_api.get_refund_details_by_payment_id(PAYU_AUTH_HEADER, PAYU_KEY, PAYMENT_ID)

Goto PayU Money Developer Docs (https://developer.payumoney.com/redirect/) for detailed documentation and to understand utility of hasher module

Goto PayU Money Developer Docs (https://www.payumoney.com/dev-guide/apireference.html) for detailed documentation and to understand utility of api package