Advertisement
bagsari

razorpay

Aug 13th, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | Cryptocurrency | 0 0
  1. import razorpay
  2. import requests
  3.  
  4. # Your API credentials
  5. api_key = "your_api_key"
  6. api_secret = "your_api_secret"
  7.  
  8. # Initialize Razorpay client
  9. client = razorpay.Client(auth=(api_key, api_secret))
  10.  
  11. # Beneficiary Account Details
  12. beneficiary = {
  13.     "name": "John Doe",
  14.     "account_number": "1234567890",
  15.     "ifsc": "HDFC0001234",
  16.     "type": "bank_account",
  17.     "email": "johndoe@example.com",
  18.     "contact": "+919999999999"
  19. }
  20.  
  21. # Create a contact (a beneficiary)
  22. contact_response = client.contact.create({
  23.     "name": beneficiary["name"],
  24.     "email": beneficiary["email"],
  25.     "contact": beneficiary["contact"],
  26.     "type": "customer",
  27.     "reference_id": "cust_001",
  28.     "notes": {
  29.         "note_key_1": "note_value_1"
  30.     }
  31. })
  32.  
  33. # Get the contact_id from the response
  34. contact_id = contact_response['id']
  35.  
  36. # Create a fund account
  37. fund_account_response = client.fund_account.create({
  38.     "contact_id": contact_id,
  39.     "account_type": beneficiary["type"],
  40.     "bank_account": {
  41.         "name": beneficiary["name"],
  42.         "ifsc": beneficiary["ifsc"],
  43.         "account_number": beneficiary["account_number"]
  44.     }
  45. })
  46.  
  47. # Get the fund_account_id from the response
  48. fund_account_id = fund_account_response['id']
  49.  
  50. # Create a payout
  51. payout_response = client.payout.create({
  52.     "account_number": "your_razorpay_account_number",  # Your Razorpay account number
  53.     "fund_account_id": fund_account_id,
  54.     "amount": 10000,  # Amount in smallest currency unit (e.g., paise for INR)
  55.     "currency": "INR",
  56.     "mode": "IMPS",  # Other modes can be NEFT, RTGS, UPI
  57.     "purpose": "refund",
  58.     "queue_if_low_balance": True,
  59.     "reference_id": "payout_001",
  60.     "narration": "Payout for Order #001",
  61.     "notes": {
  62.         "notes_key_1": "notes_value_1"
  63.     }
  64. })
  65.  
  66. # Print the payout status
  67. print("Payout Status:", payout_response['status'])
  68.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement