python
Get payment method response from strip
March 13, 2024
@http.route(['/get/card/details'],type='http',methods=['POST','GET'],auth='user',website=True,sitemap=False,csrf=False)
def get_stripe_card_details(self):
print("___________________________get struoe card detauls_________________________________________")
# Construct the URL for the Stripe API endpoint
url = 'https://api.stripe.com/v1/customers/cus_PMMZs3zNgicbrA/cards/pm_1OXdprHPKmnOIzyTLylyxuDo'
payment_acquirer = request.env['payment.acquirer'].sudo().search([('website_id','=',request.website.id),('provider','=','stripe')])
print(payment_acquirer.stripe_secret_key,"============================================================")
api_key=""
if payment_acquirer.stripe_secret_key:
api_key = payment_acquirer.stripe_secret_key
import stripe
stripe.api_key = api_key
payemnt_emthod=stripe.PaymentMethod.retrieve("pm_1OtqNlHPKmnOIzyTK1pTPesz")
print(payemnt_emthod,"_______________________________payment methoddd___________________________________")
try:
# Make the GET request to the Stripe API
print(api_key,"++++++++++++++++++++++++++++++++++++++++")
response = requests.get(url, auth=(api_key, ''))
print("______________________________response______________________",response)
# Check if the request was successful (status code 200)
if response.status_code == 200:
# Parse the JSON response
card_details = response.json()
print("______________________________card details_____________________________________",card_details)
# return card_details
else:
# Handle error response-
print(f"Failed to retrieve card details. Status code: {response}")
# return None
except Exception as e:
# Handle exceptions
print(f"Error: {e}")
# return None
Was this helpful?
Similar Posts
- [Python] The get() method on Python dicts and its "default" arg
- Get string length using len() method python
- Use separator in print() method of python
- To get url param details from get request in Django
- [Python] Get nodeid, module, function name using Pytest request built-in fixture
- [Python] Using inspect.stack() to get module name, path, function name
- Get tofixed of a value using round() Python