示例#1
0
def payment_update():
    data = request.form
    if "uid" in data:
        uid = data.get("uid")
        update_payment_item(uid, data)
    elif "date_from" in data and "date_to" in data:
        registry_date_from = datetime.strptime(data.get("date_from"),
                                               "%Y-%m-%d")
        registry_date_to = datetime.strptime(data.get("date_to"),
                                             "%Y-%m-%d") + timedelta(days=1)
        fake_registry = get_payments_registry_fake(registry_date_from,
                                                   registry_date_to)
        if fake_registry:
            registry = fake_registry
        else:
            registry = get_payments_registry(registry_date_from,
                                             registry_date_to)
        if registry and registry.get("messages") is not None:
            for message in registry.get("messages"):
                item = find_payment_item(message) or {}
                payment_status = message.pop("status", None)
                if payment_status and payment_status == "success" and item.get(
                        "payment") != message:
                    uid = item.get("_id")
                    update_payment_item(uid, message)
    return redirect(request.referrer
                    or url_for("payments_views.payment_request"))
示例#2
0
def payment_request():
    kwargs = get_request_params()
    date_from = kwargs.get("date_from")
    date_to = kwargs.get("date_to")
    rows = []
    fake_registry = None
    if date_from and date_to:
        registry_date_from = date_from
        registry_date_to = date_to + timedelta(days=1)
        fake_registry = get_payments_registry_fake(registry_date_from,
                                                   registry_date_to)
        if fake_registry:
            registry = fake_registry
        else:
            registry = get_payments_registry(registry_date_from,
                                             registry_date_to)
        if registry:
            for message in registry.get("messages", []):
                item = find_payment_item(message) or {}
                payment_status = message.pop("status", None)
                rows.append({
                    "status": payment_status,
                    "message": message,
                    "item": item.get("payment"),
                    "uid": item.get("_id"),
                    "created": item.get("createdAt"),
                    "updated": item.get("updatedAt"),
                })
    return render_template("payments/payment_request.html",
                           rows=rows,
                           fake=fake_registry is not None,
                           **kwargs)
示例#3
0
    def test_get_payments_registry_fake_shelve_registry_unset(self, shelve):
        date_from = datetime.now() - timedelta(days=2)
        date_to = datetime.now() - timedelta(days=1)
        shelve.open.return_value.__enter__.return_value = {"registry": None}

        result = get_payments_registry_fake(date_from, date_to)

        shelve.open.assert_called_once_with('payments.db')
        self.assertIsNone(result)
示例#4
0
    def test_get_payments_registry_fake_shelve_registry_empty_list(
            self, shelve):
        date_from = datetime.now() - timedelta(days=2)
        date_to = datetime.now() - timedelta(days=1)
        shelve.open.return_value.__enter__.return_value = {"registry": []}

        result = get_payments_registry_fake(date_from, date_to)

        shelve.open.assert_called_once_with('payments.db')
        self.assertEqual(result, {"status": "success", "messages": []})
示例#5
0
    def test_get_payments_registry_fake_not_in_range(self, shelve):
        date_from = datetime.now() - timedelta(days=2)
        date_to = datetime.now() - timedelta(days=1)
        shelve.open.return_value.__enter__.return_value = {
            "registry": [{
                "date_oper":
                datetime.now().strftime("%d.%m.%Y %H:%M:%S")
            }]
        }

        result = get_payments_registry_fake(date_from, date_to)

        shelve.open.assert_called_once_with('payments.db')
        self.assertEqual(result, {"status": "success", "messages": []})