Esempio n. 1
0
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_data()
     self.client = app.test_client()
     builder = EnvironBuilder(method='POST')
     self.post_env = builder.get_environ()
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_data()
     self.client = app.test_client()
     ic = ItemCollection.query.first()
     self.resp = self.client.get('/ic/{ic}'.format(ic=ic.id), headers=[('X-Requested-With', 'XMLHttpRequest'), ('Origin', app.config['BASE_URL'])])
Esempio n. 3
0
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_for('test')
     db.create_all()
     init_data()
     self.client = app.test_client()
Esempio n. 4
0
def reprocess_successful_payment(order_id):
    order = Order.query.get(order_id)
    if not order.is_confirmed:
        order_amounts = order.get_amounts(LINE_ITEM_STATUS.PURCHASE_ORDER)
        online_payment = order.online_payments[0]
        online_payment.confirm()
        db.session.add(online_payment)
        # Only INR is supported as of now
        transaction = PaymentTransaction(
            order=order,
            online_payment=online_payment,
            amount=order_amounts.final_amount,
            currency=CURRENCY.INR,
        )
        db.session.add(transaction)
        order.confirm_sale()
        db.session.add(order)
        invoice_organization = order.organization.invoicer if order.organization.invoicer else order.organization
        invoice = Invoice(order=order, organization=invoice_organization)
        db.session.add(invoice)
        db.session.commit()
        for line_item in order.line_items:
            line_item.confirm()
            db.session.add(line_item)
            if line_item.discount_coupon:
                line_item.discount_coupon.update_used_count()
                db.session.add(line_item.discount_coupon)
        db.session.commit()
        with app.test_request_context():
            send_receipt_mail.queue(order.id)
            return make_response(jsonify(message="Payment verified"), 201)
Esempio n. 5
0
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_data()
     self.client = app.test_client()
     builder = EnvironBuilder(method='POST')
     self.post_env = builder.get_environ()
Esempio n. 6
0
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_for('test')
     db.create_all()
     init_data()
     self.client = app.test_client()
Esempio n. 7
0
def process_payment(order_id, pg_paymentid):
    order = Order.query.get(order_id)
    order_amounts = order.get_amounts(LINE_ITEM_STATUS.PURCHASE_ORDER)

    online_payment = OnlinePayment.query.filter_by(
        pg_paymentid=pg_paymentid, order=order
    ).first()
    if online_payment is None:
        online_payment = OnlinePayment(pg_paymentid=pg_paymentid, order=order)

    rp_resp = razorpay.capture_payment(
        online_payment.pg_paymentid, order_amounts.final_amount
    )
    if rp_resp.status_code == 200:
        online_payment.confirm()
        db.session.add(online_payment)
        # Only INR is supported as of now
        transaction = PaymentTransaction(
            order=order,
            online_payment=online_payment,
            amount=order_amounts.final_amount,
            currency=CURRENCY.INR,
        )
        db.session.add(transaction)
        order.confirm_sale()
        db.session.add(order)
        invoice_organization = (
            order.organization.invoicer
            if order.organization.invoicer
            else order.organization
        )
        invoice = Invoice(order=order, organization=invoice_organization)
        db.session.add(invoice)
        db.session.commit()
        for line_item in order.line_items:
            line_item.confirm()
            db.session.add(line_item)
            if line_item.discount_coupon:
                line_item.discount_coupon.update_used_count()
                db.session.add(line_item.discount_coupon)
        db.session.commit()
        with app.test_request_context():
            send_receipt_mail.queue(order.id)
            return make_response(jsonify(message="Payment verified"), 201)
    else:
        online_payment.fail()
        db.session.add(online_payment)
        db.session.commit()
        raise PaymentGatewayError(
            "Online payment failed for order - {order} with the following details - {msg}".format(
                order=order.id, msg=rp_resp.content
            ),
            424,
            'Your payment failed. Please try again or contact us at {email}.'.format(
                email=order.organization.contact_email
            ),
        )
Esempio n. 8
0
def post_stats(id, webhook_url):
    with app.test_request_context():
        item_collection = ItemCollection.query.get(id)
        tickets = ticket_stats(item_collection)
        stats = ":moneybag: " + item_collection.title + "\n```" + tickets + "```"
        data = {"username": "******", "text": stats}
        response = requests.post(webhook_url, data=json.dumps(data))

        # TODO: Debug error code, maybe retry?
        if response.status_code != 200:
            pass
def post_stats(id, webhook_url):
    with app.test_request_context():
        item_collection = ItemCollection.query.get(id)
        tickets = ticket_stats(item_collection)
        stats = ":moneybag: " + item_collection.title + "\n```" + tickets + "```"
        data = {"username": "******", "text": stats}
        response = requests.post(webhook_url, data=json.dumps(data))

        # TODO: Debug error code, maybe retry?
        if response.status_code != 200:
            pass
Esempio n. 10
0
def partial_refund(**kwargs):
    """
    Processes a partial refund for an order.
    Params are order_id, amount, internal_note, refund_description, note_to_user
    """
    form_dict = {
        'amount': kwargs['amount'],
        'internal_note': kwargs['internal_note'],
        'refund_description': kwargs['refund_description'],
        'note_to_user': kwargs['note_to_user'],
    }
    order = Order.query.get(kwargs['order_id'])

    with app.test_request_context():
        process_partial_refund_for_order(order, form_dict)
Esempio n. 11
0
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_data()
     self.client = app.test_client()
Esempio n. 12
0
 def setUp(self):
     self.ctx = app.test_request_context()
     self.ctx.push()
     init_data()
     self.client = app.test_client()