Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2/2] Affiliate program Integration v1 #564

Merged
merged 80 commits into from
Nov 14, 2023

Conversation

sashko9807
Copy link
Member

@sashko9807 sashko9807 commented Oct 19, 2023

Closes #512

Motivation and context

Opens donation API for 3rd parties

Testing

Steps to test

1.Creating corporate profile

Endpoint

POST http://localhost:5010/api/v1/register

Body

{
    "type": "corporate",
    "companyName": "Association Podkrepi BG",
    "companyNumber": "206398075",
    "email": "[email protected]",
    "password": "$ecurePa33",
    "firstName": "John",
    "lastName": "Doe"
}

2.Activate new profile from keycloak

https://localhost:8180 -> login -> webapp realm -> Users -> View all users -> Click on profile with [email protected] -> User enabled -> Save

3. Join affiliate program

  1. Login with the email and password from above, through /login endpoint
  2. Copy the returned accessToken.
  3. Send request to the below endpoint, with the accessToken copied from above set in the Authorization header.(If prisma studio is started, a new affiliate should be seen with status pending
POST http://localhost:5010/api/v1/affiliate/join

4. Activating affiliate

  1. Login with admin user and copy the accessToken, and attach it to the Authorization header for the request below.
  2. Send request to the below endpoint, where affiliateId, is the id of the requested affiliate

Endpoint

PATCH http://localhost:5010/api/v1/affiliate/:affiliateId/status

Body

{
    "newStatus": "active"
}
  1. When viewing Affiliate table in Prisma studio, the affiliate's status should be active and affiliateCode should be with value with structure af_xxxxx.

5. Creating affiliate donations

Endpoint

POST http://localhost:5010/api/v1/affiliate/:affiliateCode/donation

Body

{
    "amount": 50000,
    "billingName": "John doe",
    "campaignId": ":campaignId",
    "isAnonymous": false
}

6. Cancelling affiliate donation

Endpoint

PATCH http://localhost:5010/api/v1/affiliate/:affiliateCode/donations/:donationId/cancel

7. Testing IRIS Response

Endpoint

POST http://localhost:5010/api/v1/bank-transaction/iris-transaction-test

Body

{
    "irisIbanAccountInfo" : {
        "iban": "BG80BNBG96611020345678",
        "bankName": "UniCredit"
    },
    "irisTransactionInfo": [{
        "transactionId": "Booked_5954782144_70123543493054963FTRO23073A58G01C2023345440_20230320",
        "bookingDate": "2023-03-17",
        "creditorAccount": {
            "iban": "BG66UNCR70001524349032"
        },
        "creditorName": "СДРУЖЕНИЕ ПОДКРЕПИ БГ",
        "debtorAccount": {
            "iban": "BG66UNCR70001524349032"
        },
        "debtorName": "JOHN DOE",
        "remittanceInformationUnstructured": ":affiliateCode",
        "transactionAmount": {
            "amount": 5000,
            "currency": "BGN"
        },
        "exchangeRate": null,
        "valueDate": "2023-03-14",
        "creditDebitIndicator": "CREDIT"        
    }   
    ]
}

New endpoints

Affiliate

/affiliate/join - Endpoint through which corporate user can request to join affiliate program
/affiliate/:affiliateId/status-update - Admin only Endpoint through which affiliate's status can be updated (e.g active, rejected etc.)
/affiliate/:affiliateCode/donation - Endpoint through which active affiliates can make guaranteed donations
/affiliate/:affiliateCode/donations/:donationId/cancel - Endpoint through which active affiliates can cancel guaranteed donation.

Bank Transactions

/bank-transaction/iris-transaction-test - ADMIN/AFFILIATES ONLY DEV ENVIROMENT ONLY Endpoint through which an IRIS response can be simulated

@github-actions
Copy link

github-actions bot commented Oct 19, 2023

✅ Tests will run for this PR. Once they succeed it can be merged.

@sashko9807 sashko9807 marked this pull request as ready for review October 21, 2023 09:51
@sashko9807 sashko9807 changed the title Affiliate program Integration v1 [2/2] Affiliate program Integration v1 Oct 21, 2023
@BogoCvetkov
Copy link
Contributor

Currently the PR says there are 250 files changed, where probably 80% of them were just de-formated -> something that happens when new migrations are generated when running npm prisma migrate dev. Maybe it's a good idea to run yarn format to re-format the files as they were before that, so that they don't appear here as changes and we can focus on the files that contain the new logic

@sashko9807
Copy link
Member Author

Currently the PR says there are 250 files changed, where probably 80% of them were just de-formated -> something that happens when new migrations are generated when running npm prisma migrate dev. Maybe it's a good idea to run yarn format to re-format the files as they were before that, so that they don't appear here as changes and we can focus on the files that contain the new logic

Done. Sorry for that.

@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Oct 22, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Oct 22, 2023
Comment on lines +181 to +183
person: {
firstName: user.given_name,
lastName: user.family_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a big problem, but still the user names should be already available in the session on the frontend

@@ -352,6 +354,12 @@ export class AuthService {

async changeEnabledStatus(keycloakId: string, enabled: boolean) {
await this.authenticateAdmin()
// check if user is admin before attempting to activate/deactivate
const userGroups = await this.admin.users.listRoleMappings({ id: keycloakId })
const isAdmin = userGroups.realmMappings?.some((obj) => obj.name === 'podkrepi-admin')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

who is setting this role? so far we were using the ViewSupporters role for that

Comment on lines 19 to 21
@Type(() => TExtraData)
@IsOptional()
//eslint-disable-next-line
extraData: any
extraData: TExtraData | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be good to add an example here of the expected structure, because my old mind fails to compile it ;)

…t being sent

Apparently the latest changes broke the extraData field.
 - Removed the unecessary dto extension, as it is enough to validated whether the extraData is Object
 - Used more specific type of the expected request body of extraData
In keycloak admin access is granted through team-support role - which is compose of view-supporters, view-contact-requests.
@igoychev igoychev added the run tests Allows running the tests workflows for forked repos label Nov 14, 2023
@github-actions github-actions bot removed the run tests Allows running the tests workflows for forked repos label Nov 14, 2023
@igoychev igoychev merged commit 22ffb13 into podkrepi-bg:master Nov 14, 2023
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[AffiliateAPI] Create API for Affiliates to submit donations
3 participants