def order_is_paid(self): if self.order_id is None: return False order_cls = get_order_class() order = order_cls.query.get(self.order_id) return order and order.state == OrderStates.paid
def __capture_payment(self, response): """ Final step. The payment can be captured (collected) using the DoExpressCheckoutPayment call. """ order_cls = get_order_class() self.order = order_cls.get_by_payment_details( {'token': response['TOKEN']}) if self.order is None or self.order.state is not OrderStates.created: return redirect( url_for('payment.error_payment', payment_method=self.method_name)) request_params = { 'METHOD': DO_PAYMENT, 'TOKEN': response['TOKEN'], 'PAYERID': response['PAYERID'], 'PAYMENTREQUEST_0_AMT': self.order.total_price, 'PAYMENTREQUEST_0_PAYMENTACTION': ACTION, 'PAYMENTREQUEST_0_CURRENCYCODE': CURRENCY, } response = self.__do_request(request_params) if response['ACK'] == RESPONSE_OK: self.order.set_payment_details(token=unicode(response)) self.order.mark_paid() return redirect( url_for('payment.success_payment', payment_method=self.method_name)) return redirect( url_for('payment.error_payment', payment_method=self.method_name, order_id=self.order.id))
def __capture_payment(self, response): """ Final step. The payment can be captured (collected) using the DoExpressCheckoutPayment call. """ order_cls = get_order_class() self.order = order_cls.get_by_payment_details( {'token': response['TOKEN']} ) if self.order is None or self.order.state is not OrderStates.created: return redirect(url_for('payment.error_payment', payment_method=self.method_name)) request_params = { 'METHOD': DO_PAYMENT, 'TOKEN': response['TOKEN'], 'PAYERID': response['PAYERID'], 'PAYMENTREQUEST_0_AMT': self.order.total_price, 'PAYMENTREQUEST_0_PAYMENTACTION': ACTION, 'PAYMENTREQUEST_0_CURRENCYCODE': CURRENCY, } response = self.__do_request(request_params) if response['ACK'] == RESPONSE_OK: self.order.set_payment_details(token=unicode(response)) self.order.mark_paid() return redirect(url_for('payment.success_payment', payment_method=self.method_name)) return redirect(url_for('payment.error_payment', payment_method=self.method_name, order_id=self.order.id))
def __capture_payment(self, response): """ Final step. The payment can be captured (collected) using the DoExpressCheckoutPayment call. """ order_cls = get_order_class() self.order = order_cls.get_by_payment_details( {'token': response['TOKEN']}) if self.order is None or self.order.state is not OrderStates.created: return redirect( url_for('payment.error_payment', payment_method=self.method_name)) request_params = { 'METHOD': DO_PAYMENT, 'TOKEN': response['TOKEN'], 'PAYERID': response['PAYERID'], } variant_ids = self.order.product_variants_ids if len(variant_ids) > 1: raise PaypalDataError("Ordered more then 1 variant: %r" % variant_ids) variant_id = list(variant_ids)[0] goods, trash = self.order.get_goods_delivery_for_variant(variant_id) for idx, item in enumerate(goods): invoice_id = self.gen_invoice_id(self.order.id, item.id) request_params.update({ 'PAYMENTREQUEST_{}_PAYMENTREQUESTID'.format(idx): invoice_id, 'PAYMENTREQUEST_{}_AMT'.format(idx): item.price, 'PAYMENTREQUEST_{}_PAYMENTACTION'.format(idx): ACTION, 'PAYMENTREQUEST_{}_CURRENCYCODE'.format(idx): CURRENCY, 'PAYMENTREQUEST_{}_SELLERPAYPALACCOUNTID'.format(idx): self.settings['EMAIL'], }) response = self.__do_request(request_params) if response['ACK'] in RESPONSE_OK: self.order.set_payment_details(token=unicode(response)) self.order.mark_paid() return redirect( url_for('payment.success_payment', payment_method=self.method_name)) return redirect( url_for('payment.error_payment', payment_method=self.method_name, order_id=self.order.id))
def verify(self, data): status = http.OK try: data = self.validation.check(data) variant_id = data.pop('variant') order_cls = get_order_class() order = order_cls.get_by_payment_details(data) if order is not None: data.update({ 'status': 'EXISTS', 'order': order.as_dict() }) return jsonify_status_code(data, status) variant = BaseProductVariant.objects(id=variant_id).first() if variant is None: current_app.logger.debug("No variant") raise t.DataError({'deal': _('Invalid deal')}) option, deal = self.__filter_option(variant, data['deal']) if option is None: current_app.logger.debug("No option") raise t.DataError({'deal': _('Invalid deal')}) validation = self.__validate(voucher=data['voucher'], security=data['code'], deal=data['deal']) current_app.logger.info("Validation response: %s", validation) if validation.status_code != http.OK: raise t.DataError({'voucher': _('Invalid voucher')}) session['valid_option'] = str(option.id) data.update({ 'status': 'OK', 'seats': deal['number'], 'option': option, }) except t.DataError as e: data.update({ 'status': 'ERR', 'errors': e.as_dict() }) return jsonify_status_code(data, status)
def __capture_payment(self, response): """ Final step. The payment can be captured (collected) using the DoExpressCheckoutPayment call. """ order_cls = get_order_class() self.order = order_cls.get_by_payment_details( {'token': response['TOKEN']} ) if self.order is None or self.order.state is not OrderStates.created: return redirect(url_for('payment.error_payment', payment_method=self.method_name)) request_params = { 'METHOD': DO_PAYMENT, 'TOKEN': response['TOKEN'], 'PAYERID': response['PAYERID'], } variant_ids = self.order.product_variants_ids if len(variant_ids) > 1: raise PaypalDataError("Ordered more then 1 variant: %r" % variant_ids) variant_id = list(variant_ids)[0] goods, trash = self.order.get_goods_delivery_for_variant(variant_id) for idx, item in enumerate(goods): invoice_id = self.gen_invoice_id(self.order.id, item.id) request_params.update({ 'PAYMENTREQUEST_{}_PAYMENTREQUESTID'.format(idx): invoice_id, 'PAYMENTREQUEST_{}_AMT'.format(idx): item.price, 'PAYMENTREQUEST_{}_PAYMENTACTION'.format(idx): ACTION, 'PAYMENTREQUEST_{}_CURRENCYCODE'.format(idx): CURRENCY, 'PAYMENTREQUEST_{}_SELLERPAYPALACCOUNTID'.format(idx): self.settings['EMAIL'], }) response = self.__do_request(request_params) if response['ACK'] in RESPONSE_OK: self.order.set_payment_details(token=unicode(response)) self.order.mark_paid() return redirect(url_for('payment.success_payment', payment_method=self.method_name)) return redirect(url_for('payment.error_payment', payment_method=self.method_name, order_id=self.order.id))
def verify(self, data): status = http.OK try: data = self.validation.check(data) variant_id = data.pop('variant') order_cls = get_order_class() order = order_cls.get_by_payment_details(data) if order is not None: data.update({'status': 'EXISTS', 'order': order.as_dict()}) return jsonify_status_code(data, status) variant = BaseProductVariant.objects(id=variant_id).first() if variant is None: current_app.logger.debug("No variant") raise t.DataError({'deal': _('Invalid deal')}) option, deal = self.__filter_option(variant, data['deal']) if option is None: current_app.logger.debug("No option") raise t.DataError({'deal': _('Invalid deal')}) validation = self.__validate(voucher=data['voucher'], security=data['code'], deal=data['deal']) current_app.logger.info("Validation response: %s", validation) if validation.status_code != http.OK: raise t.DataError({'voucher': _('Invalid voucher')}) session['valid_option'] = str(option.id) data.update({ 'status': 'OK', 'seats': deal['number'], 'option': option, }) except t.DataError as e: data.update({'status': 'ERR', 'errors': e.as_dict()}) return jsonify_status_code(data, status)
def cancel_payment(payment_method): sentry.captureMessage('Payment cancelled') get_order_class().cancel_payment(payment_method=payment_method, **request.args.to_dict()) return render_template('payment/cancel.html')
def cancel_payment(payment_method): get_order_class().cancel_payment(payment_method=payment_method, **request.args.to_dict()) return render_template('payment/cancel.html')