def METHOD_NAME(provider, externalID, duration=None):
    existingRecord = db.external_payments.find_one({
        "Provider": provider,
        "ExternalID": externalID,
        "$or": [
                {"Expiry": {"$exists": False}},
                {"Expiry": None},
                {"Expiry": {"$gte": datetime.utcnow()}}
            ]
        })
    if existingRecord is None:
        existingRecord = {
            "Provider": provider,
            "ExternalID": externalID,
            "Timestamp": datetime.utcnow(),
            "Expiry": datetime.utcnow() + duration if duration else None
        }
        db.external_payments.insert(existingRecord)
    return existingRecord