python

Get payment method response from strip

@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?