Exemplo n.º 1
0
    def get_form(self, payment, data={}):
        if not data:
            data = {}

        if not self.express_payments:
            pay_link = self.create_order(payment, self.get_processor(payment))
            raise RedirectNeeded(pay_link)

        cvv_url = None
        if payment.extra_data:
            extra_data = json.loads(payment.extra_data)
            if "3ds_url" in extra_data:
                raise RedirectNeeded(extra_data["3ds_url"])
            cvv_url = extra_data.get("cvv_url", None)

        if payment.status != PaymentStatus.WAITING:
            return PaymentErrorForm()

        renew_token = payment.get_renew_token()
        if renew_token and self.recurring_payments and not cvv_url:
            return RenewPaymentForm(provider=self, payment=payment)
            # Use this, if the user doesn't need to be informed about the recurring payment:
            # raise RedirectNeeded(payment.get_process_url())

        payu_data = {
            "merchant-pos-id": self.pos_id,
            "shop-name": self.payu_shop_name,
            "total-amount": payment.total,
            "currency-code": payment.currency,
            "customer-language": "en",
            "success-callback": "cardSuccess",
        }
        if cvv_url:
            payu_data.update({
                "cvv-url": cvv_url,
                "cvv-success-callback": "cvvSuccess",
                "widget-type": "cvv",
            })
        else:
            payu_data.update({
                "customer-email":
                payment.billing_email,
                "store-card":
                str(self.payu_store_card).lower(),
                "payu-brand":
                str(self.payu_widget_branding).lower(),
            })
            if self.recurring_payments:
                payu_data["recurring-payment"] = "true"
        payu_data["sig"] = self.get_sig(payu_data)

        return WidgetPaymentForm(
            payu_base_url=self.payu_base_url,
            data=data,
            script_params=payu_data,
            provider=self,
            payment=payment,
        )
Exemplo n.º 2
0
    def get_form(self, payment, data=None):
        '''
        Bank transfer gets stored and need to be done by the user
        '''
        if payment.status == PaymentStatus.WAITING:
            payment.change_status(PaymentStatus.INPUT)

        order = payment.order

        transaction_id = ''
        if order.is_recurring:
            subscription = order.subscription
            if not subscription.remote_reference:
                transaction_id = generate_transfer_code()
                subscription.remote_reference = transaction_id
                subscription.save()
            else:
                transaction_id = subscription.remote_reference

        if not payment.transaction_id:
            if not transaction_id:
                transaction_id = generate_transfer_code()
            payment.transaction_id = transaction_id
            payment.save()

        if not order.remote_reference:
            if not transaction_id:
                transaction_id = generate_transfer_code()
            order.remote_reference = transaction_id
            order.save()

        if payment.status == PaymentStatus.INPUT:
            payment.change_status(PaymentStatus.PENDING)

        raise RedirectNeeded(payment.get_success_url())
Exemplo n.º 3
0
 def get_form(self, payment: BasePayment) -> None:
     if not payment.id:
         payment.save()
     payment_data = self.create_payment(payment)
     redirect_to = self.get_value_from_response(payment_data,
                                                self.init_point)
     payment.change_status(PaymentStatus.WAITING)
     raise RedirectNeeded(redirect_to)
Exemplo n.º 4
0
    def get_form(self, payment, data=None):
        if payment.status == PaymentStatus.WAITING:
            payment.change_status(PaymentStatus.INPUT)

        form = self.form_class(data=data, payment=payment, provider=self)

        if form.is_valid():
            raise RedirectNeeded(payment.get_success_url())
        return form
Exemplo n.º 5
0
 def get_form(self, payment, data=None):
     if not payment.id:
         payment.save()
     init_payment_data = self.get_init_data(payment)
     paybox_response = self.send_request(init_payment_data)
     if paybox_response.pg_status == PayboxInitResponseStatus.ERROR:
         raise PaymentError(paybox_response.pg_error_description)
     if not self.check_response(paybox_response, self.ENDPOINT_SCRIPT_NAME):
         raise PaymentError("Invalid response(from PayBox) signature")
     raise RedirectNeeded(paybox_response.pg_redirect_url)
Exemplo n.º 6
0
    def charge_source(self, payment, source):
        try:
            charge = stripe.Charge.create(
                amount=int(payment.total * 100),
                currency=payment.currency,
                source=source.id,
            )
        except stripe.error.StripeError as e:
            payment.change_status(PaymentStatus.ERROR)
            raise RedirectNeeded(payment.get_failure_url())

        payment.transaction_id = charge.id
        payment.save()
Exemplo n.º 7
0
    def get_form(self, payment, data=None):
        if payment.status == PaymentStatus.WAITING:
            payment.change_status(PaymentStatus.INPUT)

        form = self.form_class(data=data, payment=payment, provider=self)
        if data is not None:
            if form.is_valid():
                form.save()
                raise RedirectNeeded(payment.get_success_url())

        intent = self.get_initial_intent(payment)

        if intent is not None and intent.status == 'succeeded':
            payment.change_status(PaymentStatus.CONFIRMED)
            raise RedirectNeeded(payment.get_success_url())

        if intent is not None:
            form.intent_secret = intent.client_secret
        else:
            form.intent_secret = ''
            form.action = self.get_return_url(payment)
        form.public_key = self.public_key

        return form
Exemplo n.º 8
0
 def get_form(self, payment, data=None):
     if not payment.id:
         payment.save()
     api = Instamojo(api_key=self.api_key, auth_token=self.auth_token, endpoint=self.endpoint)
     payment_request = api.payment_request_create(
         amount=payment.total,
         purpose=payment.description,
         send_email=False,
         redirect_url=self.base_url + payment.get_process_url(),
     )
     try:
         raise RedirectNeeded(payment_request['payment_request']['longurl'])
     except KeyError:
         raise PaymentError(
             'Error in processing payment. Contact developer. Output: %s' % (payment_request))
    def get_form(self, payment, data=None):
        self.payment = payment
        kwargs = {
            'data': data,
            'payment': self.payment,
            'provider': self,
            'action': '',
            'hidden_inputs': False
        }
        form = PaymentForm(**kwargs)

        if form.is_valid():
            form.save()
            raise RedirectNeeded(self.payment.get_success_url())
        else:
            self.payment.change_status('input')
        return form
Exemplo n.º 10
0
 def setup_subscription(self, payment, data=None):
     order = payment.order
     subscription = order.subscription
     plan = subscription.plan
     customer = subscription.customer
     if subscription.remote_reference:
         pass
     else:
         return_url = self.get_return_url(payment)
         subscription_data = {
             "plan_id": plan.remote_reference,
             "subscriber": {
                 "name": {
                     "given_name": customer.first_name,
                     "surname": customer.last_name
                 },
                 "email_address": customer.user_email
             },
             "application_context": {
                 "brand_name": settings.SITE_NAME,
                 "locale": settings.LANGUAGE_CODE,
                 "shipping_preference": "NO_SHIPPING",
                 "user_action": "SUBSCRIBE_NOW",
                 "payment_method": {
                     "payer_selected": "PAYPAL",
                     "payee_preferred": "IMMEDIATE_PAYMENT_REQUIRED"
                 },
                 "return_url": return_url,
                 "cancel_url": return_url,
             }
         }
         subscription_url = self.endpoint + '/v1/billing/subscriptions'
         data = self.post_api(subscription_url, subscription_data)
         subscription.remote_reference = data['id']
         subscription.save()
         approve_urls = [
             l['href'] for l in data['links'] if l['rel'] == 'approve'
         ]
         if approve_urls:
             raise RedirectNeeded(approve_urls[0])
Exemplo n.º 11
0
    def get_form(self, payment, data=None):
        client = Client(self._web_service)
        # converting rial to tooman

        amount = int(payment.total // 10)
        
        description = payment.description
        CallbackURL = payment.get_return_url()
        result = client.service.PaymentRequest(MerchantID=self._merchant_code,
                                               Amount=amount,
                                               #    email,
                                               #    mobile,
                                               Description=description,
                                               CallbackURL=CallbackURL)


        redirect_url = 'https://www.zarinpal.com/pg/StartPay/' + str(result.Authority)


        if result.Status == 100:
            payment.change_status(PaymentStatus.INPUT)
            raise RedirectNeeded(redirect_url)