# How to call Donors API source: https://developer.mastercard.com/donations/tutorial/donation-api-details/donorsapi/index.md ### Enroll donors to make it easy for them to give {#enroll-donors-to-make-it-easy-for-them-to-give} The `/donations/donors` endpoint enrolls cardholders into your donations program so they can make donations with a card on file without having to type in credit card information each time they donate. It also allows you to retrieve, update, and delete information about donors stored in the Mastercard Donate service. ## POST /donors {#post-donors} ## Pre-requisites {#pre-requisites} Before executing the test cases, acquaint yourself with the endpoint use case and parameters: * [Enroll Donor](https://developer.mastercard.com/donations/documentation/use-cases/enroll-donor/index.md) * [Create Donor Parameters](https://developer.mastercard.com/donations/documentation/parameters/enroll-manage-donor-param/enroll-donors-param/index.md) ## Test Cases {#test-cases} 1. To enroll a donor, send a POST request. 2. To create a POST request, fill out the details as shown in the request. ```py POST https://sandbox.api.mastercard.com/donations/donors ``` ```JSON { "userName":"robert.d.tester@mastercard.com", "emails":[ { "type":"home", "value":"robert.d.tester@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"123 Picket Fence Lane", "streetAddress":"2200 Mastercard Blvd", "locality":"O'Fallon", "region":"MO", "postalCode":"63368", "country":"US" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Tester", "firstName":"Robert", "honorificPrefix":"Mr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-us", "phoneNumbers":[ { "type":"work", "value":"+16367222222" } ], "password":"P@55w0rd", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"GovtID", "value":"815558847", "country":"Mexico" } ] } } ``` 3. A successful request returns the `HTTP 200 Created` status code and a JSON response body that includes a unique donor identifier. Copy and store the unique donor identifier returned in the response field `donorId`. 4. You will need this `donorId` to make calls to other endpoints. ```JSON { "donorId" : "44e15e022bb10c4ba334f7e823d4ae76dc672720", "userName" : "robert.d.tester@mastercard.com" } ``` This section discusses some of the failed scenarios and the error messages expected. 1. Send a POST request replicating the Create donor request. 2. This request fails with `400 Bad Request` error. ```JSON { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "USER_ALREADY_PRESENT", "Description": "Username already exists.", "Recoverable": false, "Details": [ "DonorId: ac9208b9-65cc-4d64-85c1-63ea703e3252" ] } ] } } ``` 1. Send this POST request with a name in the `userName` field instead of the user email ID. ```json { "userName":"myname11", "emails":[ { "type":"home", "value":"myname11@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"123 Picket Fence Lane", "streetAddress":"2200 Mastercard Blvd", "locality":"O'Fallon", "region":"MO", "postalCode":"63368", "country":"USA" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Tester", "firstName":"Robert", "honorificPrefix":"Mr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-US", "phoneNumbers":[ { "type":"work", "value":"+16367222222" } ], "password":"P@55w0rd", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"GovtID", "value":"815558847", "country":"Mexico" } ] } } ``` 2. This request fails with the error code `400 Bad Request` as only email IDs are allowed in the `userName` field. ```JSON { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "USERNAME_INVALID", "Description": "Invalid username. Must be a valid email with a maximum length of 250 characters and a local part up to 64 characters.", "Recoverable": false, "Details": null }, { "Source": "DONATE_SERVICE", "ReasonCode": "USERNAME_HOME_EMAIL_SHOULD_BE_SAME", "Description": "Username should be same as email type 'home'.", "Recoverable": false, "Details": null } ] } } ``` 1. Send this POST request with the email type as 'work' instead of 'home'. ```json { "userName":"fedup@mastercard.com", "emails":[ { "type":"work", "value":"fedup@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"Dober Lane", "streetAddress":"13 Galleliosgatan", "locality":"Hjalmar", "region":"GOT", "postalCode":"41727", "country":"SWE" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Minko", "firstName":"Meaow", "honorificPrefix":"Mr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-US", "phoneNumbers":[ { "type":"work", "value":"+16367222222" } ], "password":"P@55w0rd", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"Passport", "value":"J12345", "country":"Sweden" } ] } } ``` 2. This request fails with the error code `400 Bad Request` as it is mandatory to specify email type as 'home' when adding a donor. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "USER_EMAIL_TYPE_HOME_MANDATORY", "Description": "Email type 'home' is mandatory.", "Recoverable": false, "Details": null } ] } } ``` ## GET /donors {#get-donors} ## Pre-requisites {#pre-requisites} Before executing the test cases, acquaint yourself with the endpoint use case and parameters: * [Retrieve a Donor Profile](https://developer.mastercard.com/donations/documentation/use-cases/manage-donor/retrieve_donor/index.md) * [Parameters to Retrieve a Donor](https://developer.mastercard.com/donations/documentation/parameters/enroll-manage-donor-param/get-donor-param/index.md) ## Test Cases {#test-cases} 1. To fetch information about a donor, send a GET request. 2. Provide the `donorId` of the donor as a path parameter when fetching information about a donor. ```py GET https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 3. A successful request returns the `HTTP 200 Success` status code and a JSON response body with the donor details. ```JSON { "userName":"robert.d.tester@mastercard.com", "emails":[ { "type":"home", "value":"robert.d.tester@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"123 Picket Fence Lane", "streetAddress":"2200 Mastercard Blvd", "locality":"O'Fallon", "region":"MO", "postalCode":"63368", "country":"US" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Tester", "firstName":"Robert", "honorificPrefix":"Mr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-us", "phoneNumbers":[ { "type":"work", "value":"+16367222222" } ], "password":"P@55w0rd", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"GovtID", "value":"815558847", "country":"Mexico" } ] } } ``` If a client is associated with more than one program, it is mandatory to pass a `programID` in the header to be able to retrieve donor details associated with that specific program ID: 1. Send a GET request with the `donorId` as a path parameter. ```py GET https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. Provide the program ID in the request header: **Program ID**: 82e73e5c-f618-409a-8ca2-a212a0f649e3 3. A successful request returns the `HTTP 200 Success` status code and a JSON response body with the donor details. ```JSON { "userName":"robert.d.tester@mastercard.com", "emails":[ { "type":"home", "value":"robert.d.tester@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"123 Picket Fence Lane", "streetAddress":"2200 Mastercard Blvd", "locality":"O'Fallon", "region":"MO", "postalCode":"63368", "country":"US" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Tester", "firstName":"Robert", "honorificPrefix":"Mr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-us", "phoneNumbers":[ { "type":"work", "value":"+16367222222" } ], "password":"P@55w0rd", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"GovtID", "value":"815558847", "country":"Mexico" } ] } } ``` This section discusses some of the failed scenarios and the error messages expected. Assuming that the donor you want to retrieve is associated with multiple programs, and no program ID is provided in the header: 1. Send a GET request with the `donorId` only in the path parameter. ```py GET https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. This request fails with the error code `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "PROGRAM_ID_NOT_FOUND", "Description": "Program id is required as this client is mapped to multiple programs.", "Recoverable": false, "Details": null } ] } } ``` 1. Send a GET request with the `donorId` as a path parameter. ```py GET https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. Provide a wrong program ID in the request header: **Program ID**: 82e73e5c-f618-409a-8ca2-a212a0 3. This request fails with the error code `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "INVALID_PROGRAM_ID", "Description": "Invalid programId, it must be a valid UUID.", "Recoverable": false, "Details": null } ] } } ``` 1. Send a GET request with a `donorId` that does not exist as a path parameter. ```py GET https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76 ``` 2. This request fails with the error code `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "DONOR_ID_INVALID", "Description": "Invalid donorId, it must be a valid UUID.", "Recoverable": false, "Details": null } ] } } ``` ## PUT /donors {#put-donors} ## Pre-requisites {#pre-requisites} Before executing the test cases, acquaint yourself with the endpoint use case and parameters: * [Update a Donor Profile](https://developer.mastercard.com/donations/documentation/use-cases/manage-donor/update-donor/index.md) * [Update a Donor Parameters](https://developer.mastercard.com/donations/documentation/parameters/enroll-manage-donor-param/update-donor-param/index.md) ## Test Cases {#test-cases} 1. To update information about a donor, send a PUT request. 2. To create a PUT request, provide the `donorId` of the donor as a path parameter when updating donor information. ```py PUT https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 3. Provide details to update in the request body of the PUT request. ```JSON { "userName":"robert.d.tester@mastercard.com", "emails":[ { "type":"home", "value":"robert.d.tester@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"123 Picket Fence Lane", "streetAddress":"2200 Mastercard Blvd", "locality":"O'Fallon", "region":"MO", "postalCode":"63368", "country":"US" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Tester", "firstName":"Robert", "honorificPrefix":"Mr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-us", "phoneNumbers":[ { "type":"work", "value":"+467893018" } ], "password":"p*&xyz@q234", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"GovtID", "value":"JWPC67854", "country":"Sweden" } ] } } ``` 3. A successful request returns the `HTTP 200 Success` status code and a JSON response body that includes the unique donor identifier and the user name. ```JSON { "donorId" : "44e15e022bb10c4ba334f7e823d4ae76dc672720", "userName" : "robert.d.tester@mastercard.com" } ``` If a donor is associated with more than one program, it is mandatory to pass a `programID` in the header to be able to update donor details associated with that specific program ID: 1. Send a PUT request with the `donorId` as a path parameter. ```py PUT https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. Provide the program ID in the request header: **Program ID**: 82e73e5c-f618-409a-8ca2-a212a0f649e3 3. Provide details to update in the request body of the PUT request. ```JSON { "userName":"robert.d.tester@mastercard.com", "emails":[ { "type":"home", "value":"robert.d.tester@mastercard.com" } ], "addresses":[ { "type":"work", "formatted":"123 Picket Fence Lane", "streetAddress":"2200 Mastercard Blvd", "locality":"O'Fallon", "region":"MO", "postalCode":"63368", "country":"US" } ], "timezone":"UTC-06:00", "name":{ "lastName":"Tester", "firstName":"Robert", "honorificPrefix":"Dr.", "honorificSuffix":"Junior" }, "userType":"Online/Batch/Api", "title":"Doctor", "locale":"en-us", "phoneNumbers":[ { "type":"work", "value":"+8907893018" } ], "password":"p*&xyz@q234", "acceptedConsents":{ "privacyNoticeVersion":"PN.2-#-xr.en-us.99.01", "tncVersion":"TC.##r#12.en-us.99.99", "marketingEmailSubscribed":"N" }, "source" : "Widget", "personalInformation":{ "identifications":[ { "type":"GovtID", "value":"BAR908765", "country":"Barcelona" } ] } } ``` 4. A successful request returns the `HTTP 200 Success` status code and a JSON response body that includes the unique donor identifier and the user name. ```JSON { "donorId" : "44e15e022bb10c4ba334f7e823d4ae76dc672720", "userName" : "robert.d.tester@mastercard.com" } ``` This section discusses some of the failed scenarios and the error messages expected. Assuming that the donor you want to retrieve is associated with multiple programs, and no program ID is provided in the header: 1. Send a PUT request with the `donorId` as a path parameter. ```py PUT https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. Provide the program ID in the request header: **Program ID**: 80380ef2-5037-4e57-86bf-1bdd1efb0ae2 3. Provide details to update in the request body of the PUT request. 4. The request fails with `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "DONOR_IS_NOT_ASSOCIATED_WITH_THE_PROGRAM", "Description": "Donor is not associated with the program.", "Recoverable": false, "Details": null } ] } } ``` Assuming that the donor you want to retrieve is associated with multiple programs, and no program ID is provided in the header: 1. Send a PUT request with the `donorId` as a path parameter. ```py PUT https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. Provide a program ID and client ID not associated with each other in the request header: **Program ID** : 80380ef2-5037-4e57-86bf-1bdd1efb0ae2 **Client ID**: L99sR0H2UAGqwtzMWyDE-nfCQN1NLYQUuQd0OoSu5b9302ac 3. Provide details to update in the request body of the PUT request. 4. The request fails with `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "CLIENT_PROGRAM_NOT_ASSOCIATED", "Description": "The client with clientId 'L99sR0H2UAGqwtzMWyDE-nfCQN1NLYQUuQd0OoSu5b9302ac' is not associated with the program with programId '80380ef2-5037-4e57-86bf-1bdd1efb0ae2'.", "Recoverable": false, "Details": null } ] } } ``` ## DELETE /donors {#delete-donors} ## Pre-requisites {#pre-requisites} Before executing the test cases, acquaint yourself with the endpoint use case and parameters: * [Delete a Donor Profile](https://developer.mastercard.com/donations/documentation/use-cases/manage-donor/delete-donor/index.md) * [Delete Donor Parameters](https://developer.mastercard.com/donations/documentation/parameters/enroll-manage-donor-param/delete-donor-param/index.md) ## Test Case {#test-case} 1. To remove or delete a donor, send a DELETE request. 2. To create a DELETE request, provide the `donorId` of the donor as a path parameter when deleting a donor profile. ```py DELETE https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 3. A successful response returns the `HTTP 204 (No Content)` message. This section discusses some failed scenarios and the error messages expected. 1. Send a DELETE request with the `donorId` of a donor having active associated donation setups and cards. ```py DELETE https://sandbox.api.mastercard.com/donations/donors/c3111db9-fb41-4039-b454-2171eb4080c3 ``` 2. The request fails with `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "DELETE_USER_VALIDATION_FAILED", "Description": "Operation denied! Please remove the card(s) and the associated donation setup(s), if any, before retrying.", "Recoverable": false, "Details": null } ] } } ``` 1. Send a DELETE request with the `donorId` of a donor that was already deleted. Either ways, you can also enter a wrong `donorId` as the path parameter. ```py DELETE https://sandbox.api.mastercard.com/donations/donors/44e15e022bb10c4ba334f7e823d4ae76dc672720 ``` 2. The request fails with `400 Bad Request` as the response. ```json { "Errors": { "Error": [ { "Source": "DONATE_SERVICE", "ReasonCode": "DONOR_ID_NOT_EXIST", "Description": "Donor does not exist for the client id 'L99sR0H2UAGqwtzMWyDE-nfCQN1NLYQUuQd0OoSu5b9302ac'.", "Recoverable": false, "Details": null } ] } } ```