def post(self, request, *args, **kwargs): receipt = Receipt.objects.get(uuid=self.kwargs["uuid"]) processor = PaymentProcessor(receipt.order_item.invoice) processor.subscription_cancel(receipt) messages.info(self.request, _("Subscription Cancelled")) return redirect(request.META.get('HTTP_REFERER', self.success_url))
def post(self, request, *args, **kwargs): receipt = Receipt.objects.get(pk=self.kwargs["pk"]) subscription_id = receipt.meta.get('subscription_id', None) if not subscription_id: messages.info(self.request, _("Unable to cancel at the moment")) return redirect('vendor:customer-subscriptions') processor = PaymentProcessor(receipt.order_item.invoice) processor.cancel_subscription_payment(receipt, subscription_id) messages.info(self.request, _("Subscription Cancelled")) return redirect('vendor:customer-subscriptions')
def post(self, request, *args, **kwargs): past_receipt = Receipt.objects.get(uuid=self.kwargs["uuid"]) payment_info = {'msg': 'renewed manually'} invoice = Invoice(status=Invoice.InvoiceStatus.PROCESSING, site=past_receipt.order_item.invoice.site) invoice.profile = past_receipt.profile invoice.save() invoice.add_offer(past_receipt.order_item.offer) processor = PaymentProcessor(invoice) processor.renew_subscription(past_receipt, payment_info) messages.info(request, _("Subscription Renewed")) return redirect(request.META.get('HTTP_REFERER', self.success_url))
def test_configured_processor_setup(self): """ Test the initialized of the PaymentProcessor defined in the setting file """ try: processor = PaymentProcessor(self.invoice) except: print("Warning PaymentProcessor defined in settings file did not pass init") finally: pass
def renew_subscription_task(json_data): """ function to be added or called to a task queue to handle the the a subscription renewal. """ transaction_id = json_data['payload']['id'] dummy_invoice = Invoice() processor = payment_processor(dummy_invoice) transaction_detail = processor.get_transaction_detail(transaction_id) if not hasattr(transaction_detail, 'subscription'): return JsonResponse({}) past_receipt = Receipt.objects.filter( transaction=transaction_detail.subscription.id.text).order_by( 'created').first() payment_info = { 'account_number': transaction_detail.payment.creditCard.cardNumber.text[-4:], 'account_type': transaction_detail.payment.creditCard.cardType.text, 'full_name': " ".join([ transaction_detail.billTo.firstName.text, transaction_detail.billTo.lastName.text ]), 'raw': str(json_data) } invoice = Invoice(status=Invoice.InvoiceStatus.PROCESSING, site=past_receipt.order_item.invoice.site) invoice.profile = past_receipt.profile invoice.save() invoice.add_offer(past_receipt.order_item.offer) processor = PaymentProcessor(invoice) processor.renew_subscription(past_receipt, payment_info)
def post(self, request, *args, **kwargs): receipt = Receipt.objects.get(uuid=self.kwargs["uuid"]) payment_form = CreditCardForm(request.POST) if not payment_form.is_valid(): messages.info(request, _("Invalid Card")) return redirect(request.META.get('HTTP_REFERER', self.success_url)) processor = PaymentProcessor(receipt.order_item.invoice) processor.set_payment_info_form_data(request.POST, CreditCardForm) processor.subscription_update_payment(receipt) if not processor.transaction_submitted: messages.info( request, _(f"Payment gateway error: {processor.transaction_message.get('message', '')}" )) return redirect(request.META.get('HTTP_REFERER', self.success_url)) messages.info(request, _(f"Success: Payment Updated")) return redirect(request.META.get('HTTP_REFERER', self.success_url))