Skip to main content
PATCH
/
api
/
church
/
verifydonation
Verify Donation
curl --request PATCH \
  --url https://api.example.com/api/church/verifydonation \
  --header 'Content-Type: application/json' \
  --data '
{
  "donationId": "<string>",
  "transactionId": "<string>"
}
'
{
  "success": true,
  "message": "<string>",
  "data": {
    "data._id": "<string>",
    "data.donationName": "<string>",
    "data.donationStatus": {},
    "data.donationMetrics": {
      "data.donationMetrics.targetAmount": 123,
      "data.donationMetrics.minAmount": 123,
      "data.donationMetrics.totalGotten": 123
    },
    "data.donators": [
      {
        "data.donators[].user": {},
        "data.donators[].donated": 123,
        "data.donators[].transactionId": "<string>",
        "data.donators[].paymentVerified": true
      }
    ]
  }
}

Authentication

This endpoint requires:
  • Valid JWT token in Authorization header
  • User role must be pastor

Endpoint

PATCH /api/church/verifydonation

Request Body

donationId
string
required
The unique identifier (ObjectId) of the donation campaign.
transactionId
string
required
The Stripe checkout session ID returned when the donation was initiated. This is used to verify payment status with Stripe.

Verification Process

When a pastor verifies a donation, the following process occurs:
  1. Duplicate Check: Verifies the transaction hasn’t already been verified
  2. Transaction Lookup: Finds the donation record with the matching transactionId
  3. Stripe Verification: Retrieves the Stripe checkout session using stripe.checkout.sessions.retrieve()
  4. Payment Status Check: Confirms payment_status === "paid"
  5. Database Update:
    • Sets donators.$.paymentVerified to true
    • Increments donationMetrics.totalGotten by the donated amount
  6. Response: Returns the updated donation with populated donor information

Response

success
boolean
Indicates if the payment was verified successfully.
message
string
A human-readable message describing the verification result.
data
object
The updated donation object with populated donators.
data._id
string
Unique identifier for the donation.
data.donationName
string
Name of the donation campaign.
data.donationStatus
enum
Current status: “on”, “off”, or “completed”.
data.donationMetrics
object
Updated financial metrics.
data.donationMetrics.targetAmount
number
The fundraising goal amount.
data.donationMetrics.minAmount
number
The minimum donation amount allowed.
data.donationMetrics.totalGotten
number
Total amount received (updated after verification).
data.donators
array
Array of donator objects.
data.donators[].user
object
Populated user object with name and phoneNumber.
data.donators[].donated
number
Amount donated.
data.donators[].transactionId
string
Stripe checkout session ID.
data.donators[].paymentVerified
boolean
Payment verification status (true after verification).

Example Request

curl -X PATCH "https://api.example.com/api/church/verifydonation" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "donationId": "60d5ec49f1b2c72b8c8e4f1c",
    "transactionId": "cs_test_a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6q7R8s9T0"
  }'

Example Response

{
  "success": true,
  "message": "Payment verified",
  "data": {
    "_id": "60d5ec49f1b2c72b8c8e4f1c",
    "church": "60d5ec49f1b2c72b8c8e4f1b",
    "donationName": "Building Fund 2026",
    "donationStatus": "on",
    "startDate": "2026-04-01T00:00:00.000Z",
    "endDate": "2026-12-31T23:59:59.000Z",
    "donationDescription": "Fundraising for new church building construction",
    "bankDetails": {
      "accountName": "First Baptist Church",
      "accountNumber": "1234567890",
      "bankName": "Community Bank"
    },
    "donationSupportContact": {
      "phone": "+1-555-0123",
      "email": "[email protected]"
    },
    "donationMetrics": {
      "targetAmount": 500000,
      "minAmount": 10,
      "totalGotten": 100
    },
    "donators": [
      {
        "user": {
          "name": "John Smith",
          "phoneNumber": "+1-555-0199"
        },
        "donated": 100,
        "transactionId": "cs_test_a1B2c3D4e5F6g7H8i9J0k1L2m3N4o5P6q7R8s9T0",
        "paymentVerified": true
      }
    ],
    "createdAt": "2026-03-07T10:30:00.000Z",
    "updatedAt": "2026-03-07T11:45:00.000Z"
  }
}

Error Responses

200 - Already Verified

{
  "success": false,
  "message": "Unable to verify donations",
  "data": "This donation has already been verified"
}

200 - Payment Not Successful

{
  "success": true,
  "message": "Payment not successful",
  "error": "This payment's transaction was not successful"
}

500 - Server Error

{
  "success": false,
  "message": "Unable to verify donation",
  "data": "Error message details"
}

Stripe Integration Details

The endpoint uses the Stripe API to verify payment status:
const session = await stripe.checkout.sessions.retrieve(transactionId);
The payment is only verified if session.payment_status === "paid".

Database Operations

The verification performs an atomic update using MongoDB operators:
{
  $set: { "donators.$.paymentVerified": true },
  $inc: { "donationMetrics.totalGotten": donatedAmount }
}
This ensures:
  • The specific donator’s verification status is updated
  • The total amount received is incremented atomically
  • No race conditions occur with concurrent verifications

Notes

  • Only pastors can verify donations (role-based authorization)
  • Each transaction can only be verified once
  • The Stripe session must show payment_status: "paid"
  • The totalGotten field is automatically updated upon successful verification
  • Donator information is populated with name and phoneNumber in the response
  • Verification typically occurs within 24 hours of donation initiation

Build docs developers (and LLMs) love