Skip to content

Commit

Permalink
Merge pull request #108 from CommonGateway/feature/HP-181/documentation
Browse files Browse the repository at this point in the history
Update for sending mails
  • Loading branch information
smisidjan authored Aug 2, 2023
2 parents 3538727 + 886dc67 commit f55f3c0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 52 deletions.
10 changes: 7 additions & 3 deletions Installation/Action/hp.CreatePaymentAction.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
{
"$id": "https://hp.nl/action/hp.CreatePaymentAction.action.json",
"$schema": "https://docs.commongateway.nl/schemas/Action.schema.json",
"version": "0.0.1",
"version": "0.0.2",
"title": "CreatePaymentAction",
"description": "Create payment handler trigger.",
"listens": [
"huwelijksplanner.get.payment"
],
"throws": [],
"conditions": [],
"conditions": {
"==": [
1,
1
]
},
"class": "CommonGateway\\HuwelijksplannerBundle\\ActionHandler\\CreatePaymentHandler",
"priority": 0,
"async": false,
Expand Down
22 changes: 12 additions & 10 deletions Installation/Action/hp.HandleSendEmailAction.json

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions Installation/Action/hp.InvitePartnerAction.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"$id": "https://hp.nl/action/hp.InvitePartnerAction.action.json",
"$schema": "https://docs.commongateway.nl/schemas/Action.schema.json",
"version": "0.0.4",
"version": "0.0.5",
"title": "InvitePartnerAction",
"description": "Invite partner handler trigger.",
"listens": [
"huwelijksplanner.patch.partner"
],
"throws": [],
"conditions": [],
"class": "CommonGateway\\HuwelijksplannerBundle\\ActionHandler\\InvitePartnerHandler",
"priority": 0,
"async": false,
Expand Down
4 changes: 1 addition & 3 deletions Installation/Action/hp.InviteWitnessAction.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"$id": "https://hp.nl/action/hp.InviteWitnessAction.action.json",
"$schema": "https://docs.commongateway.nl/schemas/Action.schema.json",
"version": "0.0.4",
"version": "0.0.5",
"title": "InviteWitnessAction",
"description": "Invite witness handler trigger.",
"listens": [
"huwelijksplanner.patch.witness"
],
"throws": [],
"conditions": [],
"class": "CommonGateway\\HuwelijksplannerBundle\\ActionHandler\\InviteWitnessHandler",
"priority": 0,
"async": false,
Expand Down
7 changes: 5 additions & 2 deletions Installation/Mapping/hp.emailAndSmsDataPartner.mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
"title": "EmailAndSmsDataPartner",
"$id": "https://huwelijksplanner.nl/mapping/hp.emailAndSmsDataPartner.mapping.json",
"$schema": "https://docs.commongateway.nl/schemas/Mapping.schema.json",
"version": "0.0.2",
"version": "0.0.3",
"description": "The mapping for the assent email and sms data that is made for the partner.\n The following variables has to be filled in.\n * `body` is the body of the sms,\n * `assentName` is the name of the assent that is made for this partner,\n * `assentDescription` is the description of the assent that is made for this partner,\n * `url` is the url that the partner is directed to, to confirm the marriage\n Here you can use the \\'requesterName\\', \\'partnerName\\', \\'moment\\', \\'location\\', \\'huwelijk\\', \\'assentId\\' variables to your sentence. \n ** The requesterName is the name of the partner that requested the marriage. \n ** The partnerName is the name of the partner that is asked to get married.\n ** The `moment` is the moment of the marriage.\n ** The `location` is the location of the marriage.\n ** The `huwelijk` is the huwelijks object that is being updated.\n ** The `assentId` is the assent id that is made for the partner.",
"passTrough": false,
"mapping": {
"body": "Beste {{ partnerName }}, u bent gevraagd door {{ requesterName }} om te trouwen. Op {{ moment }} in {{ location }}. {{ requesterName }} heeft gevraagd of u dit huwelijk wilt bevestigen. https://utrecht-huwelijksplanner.frameless.io/en/voorgenomen-huwelijk/partner/login?assentId={{ assentId }}",
"header": "Melding Voorgenomen Huwelijk",
"salutation": "Beste {{ partnerName }}",
"bodyEmail": "Uw partner heeft u uitgenodigd om te loggen met DigiD. Zo bevestigt u met uw partner dat jullie het huwelijk willen regelen.",
"bodyMessage": "Beste {{ partnerName }}, u bent gevraagd door {{ requesterName }} om te trouwen. Op {{ moment }} in {{ location }}. {{ requesterName }} heeft gevraagd of u dit huwelijk wilt bevestigen. https://utrecht-huwelijksplanner.frameless.io/en/voorgenomen-huwelijk/partner/login?assentId={{ assentId }}",
"assentName": "U bent gevraagd door {{ requesterName }} om te trouwen.",
"assentDescription": "Op {{ moment }} in {{ location }}. {{ requesterName }} heeft gevraagd of u dit huwelijk wilt bevestigen.",
"url": "https://utrecht-huwelijksplanner.frameless.io/en/voorgenomen-huwelijk/partner/login?assentId={{ assentId }}"
Expand Down
7 changes: 5 additions & 2 deletions Installation/Mapping/hp.emailAndSmsDataWitness.mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
"title": "EmailAndSmsDataWitness",
"$id": "https://huwelijksplanner.nl/mapping/hp.emailAndSmsDataWitness.mapping.json",
"$schema": "https://docs.commongateway.nl/schemas/Mapping.schema.json",
"version": "0.0.2",
"version": "0.0.3",
"description": "The mapping for the assent email and sms data that is made for the partner.\n The following variables has to be filled in.\n * `body` is the body of the sms,\n * `assentName` is the name of the assent that is made for this partner,\n * `assentDescription` is the description of the assent that is made for this partner,\n * `url` is the url that the partner is directed to, to confirm the marriage\n Here you can use the \\'requesterName\\', \\'partnerName\\', \\'witnessName\\', \\'moment\\', \\'location\\', \\'huwelijk\\', \\'assentId\\' variables to your sentence. \n ** The `requesterName` is the name of the partner that requested the marriage. \n ** The `partnerName` is the name of the partner that is asked to get married.\n ** The `witnessName` is the name of the witness that is being invited.\n ** The `moment` is the moment of the marriage.\n ** The `location` is the location of the marriage.\n ** The `huwelijk` is the huwelijks object that is being updated.\n ** The `assentId` is the assent id that is made for the witness.",
"passTrough": false,
"mapping": {
"body": "Beste {{ witnessName }}, u bent gevraagd om getuigen te zijn bij het huwelijk van {{ requesterName }} en {{ partnerName }}. Op {{ moment }} in {{ location }}. {{ requesterName }} en {{ partnerName }} hebben u gevraagd om een reactie te geven op dit verzoek. https://utrecht-huwelijksplanner.frameless.io/en/voorgenomen-huwelijk/getuigen/instemmen?assentId={{ assentId }}",
"header": "Melding Voorgenomen Huwelijk",
"salutation": "Beste {{ witnessName }}",
"bodyEmail": "{{ requesterName }} en {{ partnerName }} heeft u uitgenodigd om getuigen te zijn voor hun huwelijk. Via de link kunt u de uitnodiging accepteren of weigeren.",
"bodyMessage": "Beste {{ witnessName }}, u bent gevraagd om getuigen te zijn bij het huwelijk van {{ requesterName }} en {{ partnerName }}. Op {{ moment }} in {{ location }}. {{ requesterName }} en {{ partnerName }} hebben u gevraagd om een reactie te geven op dit verzoek. https://utrecht-huwelijksplanner.frameless.io/en/voorgenomen-huwelijk/getuigen/instemmen?assentId={{ assentId }}",
"assentName": "U bent gevraagd om getuigen te zijn bij het huwelijk van {{ requesterName }} en {{ partnerName }}.",
"assentDescription": "Op {{ moment }} in {{ location }}. {{ requesterName }} {{ partnerName }} hebben u gevraagd om een reactie te geven op dit verzoek.",
"url": "https://utrecht-huwelijksplanner.frameless.io/en/voorgenomen-huwelijk/getuigen/instemmen?assentId={{ assentId }}"
Expand Down
5 changes: 4 additions & 1 deletion src/ActionHandler/InvitePartnerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function getConfiguration(): array
'type' => 'string',
'description' => 'The mapping for the assent email and sms data that is made for the partner.
The following variables has to be filled in.
* `body` is the body of the sms,
* `header` is the header of the email,
* `salutation` is the salutation of the email,
* `bodyEmail` is the body of the email,
* `bodyMessage` is the body of the sms,
* `assentName` is the name of the assent that is made for this partner,
* `assentDescription` is the description of the assent that is made for this partner,
* `url` is the url that the partner is directed to, to confirm the marriage
Expand Down
5 changes: 4 additions & 1 deletion src/ActionHandler/InviteWitnessHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public function getConfiguration(): array
'type' => 'string',
'description' => 'The mapping for the assent email and sms data that is made for the partner.
The following variables has to be filled in.
* `body` is the body of the sms,
* `header` is the header of the email,
* `salutation` is the salutation of the email,
* `bodyEmail` is the body of the email,
* `bodyMessage` is the body of the sms,
* `assentName` is the name of the assent that is made for this partner,
* `assentDescription` is the description of the assent that is made for this partner,
* `url` is the url that the partner is directed to, to confirm the marriage
Expand Down
35 changes: 9 additions & 26 deletions src/Service/HandleAssentService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function checkSourceAuth(Source $source): bool
/**
* Checks the config.
*
* @param string $config The config array from the action.
* @param array $config The config array from the action.
*
* @return array
*/
Expand Down Expand Up @@ -132,12 +132,11 @@ public function checkConfig(array $config): array
* Sends an emails.
*
* @param object $emailAddresses The emailaddresses.
* @param string $type The type of the assent.
* @param string $data The data array of the request.
* @param array $data The data array of the request.
*
* @return void
*/
public function sendEmail(object $emailAddresses, string $type, array $data): void
public function sendEmail(object $emailAddresses, array $data): void
{
// Get action.
$action = $this->gatewayResourceService->getAction('https://hp.nl/action/hp.HandleSendEmailAction.action.json', 'common-gateway/huwelijksplanner-bundle');
Expand All @@ -149,21 +148,8 @@ public function sendEmail(object $emailAddresses, string $type, array $data): vo
$configuration = $action->getConfiguration();
$config = $this->checkConfig($configuration);

switch ($type) {
case 'requester':
$config['template'] = $config['template2'];
break;
case 'partner':
$config['template'] = $config['template3'];
break;
case 'witness':
$config['template'] = $config['template4'];
break;
}

$config['serviceDNS'] = $source->getLocation().$source->getApiKey();

// ? variables and data
foreach ($emailAddresses as $emailAddress) {
// set receiver to config
$config['receiver'] = $emailAddress->getValue('email');
Expand All @@ -183,15 +169,12 @@ public function sendEmail(object $emailAddresses, string $type, array $data): vo
/**
* Sends a sms.
*
* @param object $phoneNumbers The phonenumbers.
* @param string $type The type of the assent.
*
* @param object $phoneNumbers The phonenumbers.
* @param array $data
* @return void
*/
public function sendSms(object $phoneNumbers, string $type, array $data): void
public function sendSms(object $phoneNumbers, array $data): void
{
$action = $this->gatewayResourceService->getAction('https://hp.nl/action/hp.MessageBirdAction.action.json', 'common-gateway/huwelijksplanner-bundle');

// Set the phoneNumbers to the recipients array.
$data['response']['recipients'] = [];
foreach ($phoneNumbers as $phoneNumber) {
Expand Down Expand Up @@ -256,8 +239,8 @@ public function handleAssentEmailAndSms(ObjectEntity $person, string $type, arra
$this->pluginLogger->debug('hier mail of sms versturen en een secret genereren');

if ($assent->getValue('status') !== 'granted') {
$this->sendEmail($emailAddresses, $type, $data);
$this->sendSms($phoneNumbers, $type, $data);
$this->sendEmail($emailAddresses, $data);
$this->sendSms($phoneNumbers, $data);
}

return $assent;
Expand All @@ -270,7 +253,7 @@ public function handleAssentEmailAndSms(ObjectEntity $person, string $type, arra
*
* @param ObjectEntity $person The person to make/update an assent for.
* @param string $type The type of assent.
* @param array $propertyId The id of the property this assent is about.
* @param string $propertyId The id of the property this assent is about.
* @param ObjectEntity|null $assent The assent of the person
*
* @return ObjectEntity|null
Expand Down
2 changes: 1 addition & 1 deletion src/Service/MessageBirdService.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function messageBirdHandler(?array $data=[], ?array $configuration=[]): a
$this->configuration = $configuration;

$recipients = $this->data['response']['recipients'];
$body = $this->data['response']['body'];
$body = $this->data['response']['bodyMessage'];

$message = $this->sendMessage($recipients, $body);

Expand Down

0 comments on commit f55f3c0

Please sign in to comment.