def _send_request(self): stripe_token = self.order.payment_data["stripe"].get("token") stripe_customer = self.order.payment_data["stripe"].get("customer") input_data = { "description": _("Payment for order {id} on {shop}").format( id=self.order.identifier, shop=self.order.shop, ) } if stripe_token: input_data["source"] = stripe_token elif stripe_customer: input_data["customer"] = stripe_customer input_data.update(get_amount_info(self.order.taxful_total_price)) from shuup.utils.http import retry_request return retry_request(method="post", url="https://api.stripe.com/v1/charges", data=input_data, auth=(self.secret_key, ""), headers={ "Idempotency-Key": self.order.key, "Stripe-Version": "2015-04-07" })
def post(self, request, *args, **kwargs): stripe_processor = get_stripe_processor(request) try: stripe.api_key = stripe_processor.secret_key intent = stripe.PaymentIntent.create( **get_amount_info(self.request.basket.taxful_total_price)) return JsonResponse({'clientSecret': intent['client_secret']}) except Exception as e: LOGGER.exception("Failed to create Stripe payment intent") messages.error(request, _("Unknown error while creating payment intent.")) return JsonResponse(data=str(e), status_code=403)
def get_stripe_context(self): order = self.get_object() payment_processor = order.payment_method.payment_processor publishable_key = payment_processor.publishable_key secret_key = payment_processor.secret_key if not (publishable_key and secret_key): raise Problem( _("Please configure Stripe keys for payment processor %s.") % payment_processor) config = { "publishable_key": publishable_key, "name": force_text(self.request.shop), "description": force_text(_("Purchase")), } config.update(get_amount_info(order.taxful_total_price)) return config
def _send_request(self): stripe_token = self.order.payment_data["stripe"]["token"] input_data = { "source": stripe_token, "description": _("Payment for order {id} on {shop}").format( id=self.order.identifier, shop=self.order.shop, ), } input_data.update(get_amount_info(self.order.taxful_total_price)) return retry_request( method="post", url="https://api.stripe.com/v1/charges", data=input_data, auth=(self.secret_key, "x"), headers={ "Idempotency-Key": self.order.key, "Stripe-Version": "2015-04-07" } )
def _send_request(self): stripe_source = self._fetch_source() stripe_customer = self.order.payment_data["stripe"].get("customer") input_data = { "description": _("Payment for order {id} on {shop}").format( id=self.order.identifier, shop=self.order.shop, ) } if stripe_source: input_data["source"] = stripe_source["id"] elif stripe_customer: input_data["customer"] = stripe_customer input_data.update(get_amount_info(self.order.taxful_total_price)) stripe.api_key = self.secret_key return stripe.PaymentIntent.create( **input_data, payment_method_types=["card"], )