-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Transaction Processing logic & Wallet linking implementation #6399
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
386db97
feat: Transaction Processing logic & Wallet linking implementation
mrsaicharan1 b9bf3a2
Added jwt headers
mrsaicharan1 94a1071
Merge branch 'development' into paytm-final
mrsaicharan1 8c98f26
Merge branch 'development' into paytm-final
uds5501 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import logging | ||
import json | ||
import pytz | ||
from datetime import datetime | ||
import time | ||
mrsaicharan1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import omise | ||
import requests | ||
|
||
|
||
import omise | ||
from datetime import datetime | ||
from flask import request, jsonify, Blueprint, url_for, redirect | ||
from flask_jwt_extended import current_user | ||
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship | ||
|
@@ -41,6 +41,7 @@ | |
from app.models.ticket_holder import TicketHolder | ||
from app.models.user import User | ||
|
||
|
||
order_misc_routes = Blueprint('order_misc', __name__, url_prefix='/v1') | ||
alipay_blueprint = Blueprint('alipay_blueprint', __name__, url_prefix='/v1/alipay') | ||
|
||
|
@@ -543,7 +544,6 @@ def create_paypal_payment(order_identifier): | |
else: | ||
return jsonify(status=False, error=response) | ||
|
||
|
||
@order_misc_routes.route('/orders/<string:order_identifier>/verify-mobile-paypal-payment', methods=['POST']) | ||
@jwt_required | ||
def verify_mobile_paypal_payment(order_identifier): | ||
|
@@ -629,6 +629,7 @@ def omise_checkout(order_identifier): | |
|
||
|
||
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/initiate-transaction', methods=['POST', 'GET']) | ||
@jwt_required | ||
def initiate_transaction(order_identifier): | ||
""" | ||
Initiating a PayTM transaction to obtain the txn token | ||
|
@@ -641,14 +642,14 @@ def initiate_transaction(order_identifier): | |
# body parameters | ||
paytm_params["body"] = { | ||
"requestType": "Payment", | ||
"mid": (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'sandbox' | ||
"mid": (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test' | ||
else get_settings()['paytm_live_merchant']), | ||
"websiteName": "eventyay", | ||
"orderId": order.id, | ||
"orderId": order_identifier, | ||
"callbackUrl": "", | ||
"txnAmount": { | ||
"value": order.amount, | ||
"currency": order.event.payment_currency, | ||
"currency": "INR", | ||
}, | ||
"userInfo": { | ||
"custId": order.user.id, | ||
|
@@ -660,11 +661,108 @@ def initiate_transaction(order_identifier): | |
"signature" : checksum | ||
} | ||
post_data = json.dumps(paytm_params) | ||
if paytm_mode == 'sandbox': | ||
if paytm_mode == 'test': | ||
url = "https://securegw-stage.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_sandbox_merchant'], order.id) | ||
format(get_settings()['paytm_sandbox_merchant'], order_identifier) | ||
else: | ||
url = "https://securegw.paytm.in/theia/api/v1/initiateTransaction?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_sandbox_merchant'], order.id) | ||
format(get_settings()['paytm_live_merchant'], order_identifier) | ||
response = requests.post(url, data=post_data, headers={"Content-type": "application/json"}) | ||
return response.json() | ||
|
||
|
||
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/fetch-payment-options/<string:txn_token>') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. expected 2 blank lines, found 1 |
||
@jwt_required | ||
def fetch_payment_options(order_identifier, txn_token): | ||
paytm_mode = get_settings()['paytm_mode'] | ||
if paytm_mode == 'test': | ||
url = "https://securegw-stage.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_sandbox_merchant'], order_identifier) | ||
else: | ||
url = "https://securegw.paytm.in/theia/api/v1/fetchPaymentOptions?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_live_merchant'], order_identifier) | ||
head = { | ||
"clientId": "C11", | ||
"version": "v1", | ||
"requestTimestamp": str(int(time.time())), | ||
"channelId": "WEB", | ||
"txnToken": txn_token | ||
} | ||
response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head) | ||
return response | ||
|
||
|
||
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/send_otp/<string:txn_token>', methods=['POST']) | ||
@jwt_required | ||
def send_otp(order_identifier, txn_token): | ||
paytm_mode = get_settings()['paytm_mode'] | ||
if paytm_mode == 'test': | ||
url = "https://securegw-stage.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_sandbox_merchant'], order_identifier) | ||
else: | ||
url = "https://securegw.paytm.in/theia/api/v1/login/sendOtp?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_live_merchant'], order_identifier) | ||
|
||
head = { | ||
"clientId": "C11", | ||
"version": "v1", | ||
"requestTimestamp": str(int(time.time())), | ||
"channelId": "WEB", | ||
"txnToken": txn_token | ||
} | ||
body = {"mobileNumber": request.json['data']['phone']} | ||
response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head, body=body) | ||
return response | ||
|
||
|
||
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/validate_otp/<string:txn_token>', methods=['POST']) | ||
def validate_otp(order_identifier, txn_token): | ||
paytm_mode = get_settings()['paytm_mode'] | ||
if paytm_mode == 'test': | ||
url = "https://securegw-stage.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_sandbox_merchant'], order_identifier) | ||
else: | ||
url = "https://securegw.paytm.in/theia/api/v1/login/validateOtp?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_live_merchant'], order_identifier) | ||
head = { | ||
"clientId": "C11", | ||
"version": "v1", | ||
"requestTimestamp": str(int(time.time())), | ||
"channelId": "WEB", | ||
"txnToken": txn_token | ||
} | ||
body = {"otp": request.json['data']['otp']} | ||
response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head, body=body) | ||
return response | ||
|
||
|
||
@order_misc_routes.route('/orders/<string:order_identifier>/paytm/process_transaction/<string:txn_token>') | ||
@jwt_required | ||
def process_transaction(order_identifier, txn_token): | ||
paytm_mode = get_settings()['paytm_mode'] | ||
merchant_id = (get_settings()['paytm_sandbox_merchant'] if paytm_mode == 'test' | ||
else get_settings()['paytm_live_merchant']) | ||
|
||
if paytm_mode == 'test': | ||
url = "https://securegw-stage.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_sandbox_merchant'], order_identifier) | ||
else: | ||
url = "https://securegw.paytm.in/theia/api/v1/processTransaction?mid={}&orderId={}".\ | ||
format(get_settings()['paytm_live_merchant'], order_identifier) | ||
|
||
head = { | ||
"version": "v1", | ||
"requestTimestamp": str(int(time.time())), | ||
"channelId": "WEB", | ||
"txnToken": txn_token | ||
} | ||
|
||
body = { | ||
"requestType": "NATIVE", | ||
"mid": merchant_id, | ||
"orderId": order_identifier, | ||
"paymentMode": "BALANCE" | ||
} | ||
|
||
response = PaytmPaymentsManager.hit_paytm_endpoint(url=url, head=head, body=body) | ||
return response |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected 1 blank line, found 0