コード例 #1
0
    def post(self, request, *args, **kwargs):
        stripe_processor = get_stripe_processor(request)
        stripe_token = request.POST.get("stripeToken")
        stripe_customer = None

        if stripe_token:
            person_contact = get_person_contact(self.request.user)
            stripe.api_key = stripe_processor.secret_key
            stripe_customer = StripeCustomer.objects.filter(
                contact=person_contact).first()

            try:
                if stripe_customer:
                    stripe.Customer.modify(stripe_customer.customer_token,
                                           source=stripe_token)
                else:
                    customer = stripe.Customer.create(
                        source=stripe_token, email=person_contact.email)
                    stripe_customer = StripeCustomer.objects.create(
                        contact=person_contact, customer_token=customer.id)

            except stripe.error.StripeError:
                LOGGER.exception("Failed to create Stripe Customer")
                stripe_customer = None

        if stripe_customer:
            messages.success(request, _("Payment details successfully saved."))
        else:
            messages.error(request, _("Error while saving payment details."))

        return HttpResponseRedirect(reverse("shuup:stripe_saved_payment"))
コード例 #2
0
ファイル: views.py プロジェクト: shuup/shuup-stripe
    def post(self, request, *args, **kwargs):
        stripe_processor = get_stripe_processor(request)
        stripe_token = request.POST.get("stripeToken")
        stripe_customer = None

        if stripe_token:
            person_contact = get_person_contact(self.request.user)
            stripe.api_key = stripe_processor.secret_key
            stripe_customer = StripeCustomer.objects.filter(contact=person_contact).first()

            try:
                if stripe_customer:
                    stripe.Customer.modify(stripe_customer.customer_token, source=stripe_token)
                else:
                    customer = stripe.Customer.create(source=stripe_token, email=person_contact.email)
                    stripe_customer = StripeCustomer.objects.create(
                        contact=person_contact,
                        customer_token=customer.id
                    )

            except stripe.StripeError:
                LOGGER.exception("Failed to create Stripe Customer")
                stripe_customer = None

        if stripe_customer:
            messages.success(request, _("Payment details successfully saved."))
        else:
            messages.error(request, _("Error while saving payment details."))

        return HttpResponseRedirect(reverse("shuup:stripe_saved_payment"))
コード例 #3
0
 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)
コード例 #4
0
    def post(self, request, *args, **kwargs):
        stripe_processor = get_stripe_processor(request)
        person_contact = get_person_contact(request.user)
        stripe_customer = StripeCustomer.objects.filter(contact=person_contact).first()
        source_id = request.POST.get("source_id")

        if stripe_customer and source_id:
            stripe.api_key = stripe_processor.secret_key

            try:
                customer = stripe.Customer.retrieve(stripe_customer.customer_token)
                customer.sources.retrieve(source_id).delete()
            except stripe.error.StripeError:
                LOGGER.exception("Failed to delete Stripe source")
                messages.error(request, _("Unknown error while removing payment details."))

            else:
                messages.success(request, _("Payment successfully removed."))

        return HttpResponseRedirect(reverse("shuup:stripe_saved_payment"))
コード例 #5
0
    def get_context_data(self, **kwargs):
        context = super(StripeSavedPaymentInfoView, self).get_context_data(**kwargs)
        person_contact = get_person_contact(self.request.user)
        stripe_processor = get_stripe_processor(self.request)
        stripe_customer = StripeCustomer.objects.filter(contact=person_contact).first()

        context["stripe_customer"] = stripe_customer
        context["customer"] = person_contact
        context["stripe_processor"] = stripe_processor

        if stripe_customer:
            stripe.api_key = stripe_processor.secret_key

            try:
                customer = stripe.Customer.retrieve(stripe_customer.customer_token)
                context["stripe_customer_data"] = customer.to_dict()
            except stripe.error.StripeError:
                pass

        return context
コード例 #6
0
ファイル: views.py プロジェクト: shuup/shuup-stripe
    def post(self, request, *args, **kwargs):
        stripe_processor = get_stripe_processor(request)
        person_contact = get_person_contact(request.user)
        stripe_customer = StripeCustomer.objects.filter(contact=person_contact).first()
        source_id = request.POST.get("source_id")

        if stripe_customer and source_id:
            stripe.api_key = stripe_processor.secret_key

            try:
                customer = stripe.Customer.retrieve(stripe_customer.customer_token)
                customer.sources.retrieve(source_id).delete()
            except stripe.StripeError:
                LOGGER.exception("Failed to delete Stripe source")
                messages.error(request, _("Unknown error while removing payment details."))

            else:
                messages.success(request, _("Payment successfully removed."))

        return HttpResponseRedirect(reverse("shuup:stripe_saved_payment"))
コード例 #7
0
ファイル: views.py プロジェクト: shuup/shuup-stripe
    def get_context_data(self, **kwargs):
        context = super(StripeSavedPaymentInfoView, self).get_context_data(**kwargs)
        person_contact = get_person_contact(self.request.user)
        stripe_processor = get_stripe_processor(self.request)
        stripe_customer = StripeCustomer.objects.filter(contact=person_contact).first()

        context["stripe_customer"] = stripe_customer
        context["customer"] = person_contact
        context["stripe_processor"] = stripe_processor

        if stripe_customer:
            stripe.api_key = stripe_processor.secret_key

            try:
                customer = stripe.Customer.retrieve(stripe_customer.customer_token)
                context["stripe_customer_data"] = customer.to_dict()
            except stripe.StripeError:
                pass

        return context