Commit 5034144b by jay

channel partner otp email and sms api integration.

1 parent 52fbc07b
...@@ -71,6 +71,39 @@ ...@@ -71,6 +71,39 @@
}, },
"dialCode": { "dialCode": {
"type": "string" "type": "string"
},
"httpSMSResposneBody": {
"type": "text"
},
"httpSMSRequestMethod": {
"type": "text"
},
"httpSMSRequestUrl": {
"type": "text"
},
"httpSMSRequestHeaders": {
"type": "text"
},
"httpsSMSRequestBody": {
"type": "text"
},
"thirdPartyApiError": {
"type": "boolean"
},
"httpEmailResposneBody": {
"type": "text"
},
"httpEmailRequestMethod": {
"type": "text"
},
"httpEmailRequestUrl": {
"type": "text"
},
"httpEmailRequestHeaders": {
"type": "text"
},
"httpsEmailRequestBody": {
"type": "text"
} }
} }
} }
...@@ -305,24 +305,112 @@ const userPermissionExtension = (plugin) => { ...@@ -305,24 +305,112 @@ const userPermissionExtension = (plugin) => {
const oneTimePassword = Math.floor(100000 + Math.random() * 900000); const oneTimePassword = Math.floor(100000 + Math.random() * 900000);
const emailToSend = { const emailToSend = {
oneTimePassword:oneTimePassword,
to: user.email, to: user.email,
from: from:`contact@hiranandani.net`,
resetPasswordSettings.from.email || resetPasswordSettings.from.name
? `${resetPasswordSettings.from.name} <${resetPasswordSettings.from.email}>`
: undefined,
replyTo: resetPasswordSettings.response_email, replyTo: resetPasswordSettings.response_email,
subject: `Your one time password is: ${oneTimePassword}`, subject: `Your one time password is: ${oneTimePassword}`,
text: `Hello ${channelPartner.contactPersonName}, Your one time password to login to your partner portal is ${oneTimePassword}`, text: `Hello ${channelPartner.contactPersonName}, Your one time password to login to your partner portal is ${oneTimePassword}`,
html: `<p>Hello ${channelPartner.contactPersonName}, <br></br>Your one time password to login to your partner portal is ${oneTimePassword}</p><br /> Best Regards, <br /> Team Hiranandani.`, html: `<p>Hello ${channelPartner.contactPersonName}, <br></br>Your one time password to login to your partner portal is ${oneTimePassword}</p><br /> Best Regards, <br /> Team Hiranandani.`,
}; };
const finalData = {
emailToSend: emailToSend,
mobileNo: mobileNumber,
fullName: channelPartner.contactPersonName,
};
try {
// const spertoResponse = await axios.post(
// "https://net4hgc.sperto.co.in/_api/api_auth_send_mail.php",
// otpDetails,
// { headers: headers }
// );
const spretoOTP = await strapi
.service("api::end-user.end-user")
.sendOTPToSpreto(finalData);
// console.log("spretoOTP", spretoOTP);
// EMAIL RESPONSE
ctx.request.body.httpEmailRequestHeaders = JSON.stringify(
spretoOTP.spertoEmailResponse.headers
);
ctx.request.body.httpEmailRequestMethod =
spretoOTP.spertoEmailResponse.config.method;
ctx.request.body.httpEmailRequestUrl =
spretoOTP.spertoEmailResponse.config.url;
ctx.request.body.httpsEmailRequestBody =
spretoOTP.spertoEmailResponse.config.data;
ctx.request.body.httpEmailResposneBody = JSON.stringify(
spretoOTP.spertoEmailResponse.data
);
// SMS RESPONSE
ctx.request.body.httpSMSRequestHeaders = JSON.stringify(
spretoOTP.spertoSMSResponse.headers
);
ctx.request.body.httpSMSRequestMethod =
spretoOTP.spertoSMSResponse.config.method;
ctx.request.body.httpSMSRequestUrl =
spretoOTP.spertoSMSResponse.config.url;
// ctx.request.body.httpsSMSRequestBody = spretoOTP.spertoSMSResponse.config.data;
ctx.request.body.httpSMSResposneBody = JSON.stringify(
spretoOTP.spertoSMSResponse.data
);
ctx.request.body.thirdPartyApiError = false;
// console.log("spretoOTP", spretoOTP);
// return spretoOTP;
} catch (error) {
// Email errors
ctx.request.body.httpEmailRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.httpEmailRequestMethod = error.config.method;
ctx.request.body.httpEmailRequestUrl = error.config.url;
ctx.request.body.httpsEmailRequestBody = error.config.data;
ctx.request.body.httpEmailResposneBody = JSON.stringify(error.message);
// SMS headers
ctx.request.body.httpSMSRequestHeaders = JSON.stringify(
error.config.headers
);
ctx.request.body.httpSMSRequestMethod = error.config.method;
ctx.request.body.httpSMSRequestUrl = error.config.url;
// ctx.request.body.httpsSMSRequestBody = error.config.data;
ctx.request.body.httpSMSResposneBody = JSON.stringify(error.message);
ctx.request.body.thirdPartyApiError = true;
}
// NOTE: Update the user before sending the email so an Admin can generate the link if the email fails // NOTE: Update the user before sending the email so an Admin can generate the link if the email fails
await getService("user").edit(user.id, { await getService("user").edit(user.id, {
oneTimePassword: `${oneTimePassword}`, oneTimePassword: `${oneTimePassword}`,
}); });
await strapi.entityService.update("api::channel-partner.channel-partner", channelPartner.id, {
data: {
// httpRequestIsVerifiedHeaders:
// ctx.request.body.httpRequestIsVerifiedHeaders,
// httpsRequestIsVerifiedBody: ctx.request.body.httpsRequestIsVerifiedBody,
// httpRequestIsVerifiedUrl: ctx.request.body.httpRequestIsVerifiedUrl,
// httpRequestIsVerifiedMethod:
// ctx.request.body.httpRequestIsVerifiedMethod,
// httpResposneIsVerifiedBody: ctx.request.body.httpResposneIsVerifiedBody,
// httpRequestIsVerifiedHeaders:
// ctx.request.body.httpRequestIsVerifiedHeaders,
// httpsRequestIsVerifiedBody: ctx.request.body.httpsRequestIsVerifiedBody,
httpSMSRequestUrl: ctx.request.body.httpSMSRequestUrl,
httpSMSRequestMethod: ctx.request.body.httpSMSRequestMethod,
httpSMSResposneBody: ctx.request.body.httpSMSResposneBody,
httpSMSRequestHeaders: ctx.request.body.httpSMSRequestHeaders,
httpsEmailRequestBody: ctx.request.body.httpsEmailRequestBody,
httpEmailRequestUrl: ctx.request.body.httpEmailRequestUrl,
httpEmailRequestMethod: ctx.request.body.httpEmailRequestMethod,
httpEmailResposneBody: ctx.request.body.httpEmailResposneBody,
httpEmailRequestHeaders: ctx.request.body.httpEmailRequestHeaders,
},
});
// Send an email to the user. // Send an email to the user.
await strapi.plugin("email").service("email").send(emailToSend); // await strapi.plugin("email").service("email").send(emailToSend);
// TODO: Send SMS. // TODO: Send SMS.
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!