Closed johnking closed 6 years ago
@johnking thanks for opening up the issue.
Can you clarify which app you are running and having a problem? I'm guessing it is either:
8-start
8-end
You can share your actual code in a public repo for us to review.
If the book is successfully purchased by a user, you should see the following data in your database:
Purchase
document with proper userId
and bookId
parameterspurchasedBookIds
in the User
document with proper value (id of purchased book)Do you see these data?
Hi @klyburke
The issue is related to the main repository, not about the tutorial code (book chapter-8 code).
the only changes in my clone are
-John
Thanks @johnking
To help figure out the problem, can you confirm if you see the data I mentioned in the previous comment?
- a
Purchase
document with properuserId
andbookId
parameters- a parameter
purchasedBookIds
in theUser
document with proper value (id of purchased book)
Hi @klyburke
I tried a clean deployment locally with my own secrets, and completed the purchase process with the demo-book (forked from your demo-book repository), I checked the database:
No Purchase
document inside the purchase
collect
there is parameter purchasedBookIds
in the User
document as below:
{
"_id": {
"$oid": "5b7ac4c6672fe01f04a62e89"
},
"isAdmin": false,
"purchasedBookIds": [
"5b7ac4ad672fe01f04a62e88"
],
"freeBookIds": [],
"isGithubConnected": false,
"createdAt": {
"$date": "2018-08-20T13:40:22.868Z"
},
.....
"__v": 0
}
let me know if you need more information to resolve it.
thanks
-John
@johnking Thanks for your response about DB.
The fact that your User
doc has purchasedBookIds
(line 237 does run) but Purchase
doc is not created (line 265 does not run) - means that either AWS SES or Mailchimp returned caught error. As a result code that creates Purchase
doc did not run.
Please take a look at below snippet: https://github.com/builderbook/builderbook/blob/146ade6be3f39261d174360a08cd55921667bd03/server/models/Book.js#L237-L272
Clear DB and try purchasing book again.
Please monitor logs in your terminal, you should see either server error:
logger.error('Email sending error:', error);
or
logger.error('Mailchimp error:', error);
Once you see the error, you can confirm it further by commenting out either AWS SES- or Mailchimp-related block of code and purchasing book again (remember to either clear DB or remove purchasedBookIds
from User
doc).
@klyburke Thanks for narrowing down on potential problem.
Hi @tima101 @klyburke ,
I repeated the steps based on your instructions, but I did not find any log errors related to AWS SES or Mailchimp, and I did not receive the purchase notification email either. I could receive the notification email based on chapter 8-end code.
both the console logs and in-application message give me a not found
error message.
The DB has the same status, there is no Purchase
document created inside the purchase
collection.
@johnking Alright, this helps to narrow down problem even further. You did not get purchase email via AWS SES. Was your email address added to Mailchimp list?
Please comment out these 2 blocks of code and test purchase again (remember to clear relevant data in DB):
const template = await getEmailTemplate('purchased', {
userName: user.displayName,
bookTitle: book.name,
bookUrl: `https://builderbook.org/books/${book.slug}/introduction`,
});
try {
await sendEmail({
from: `Kelly from builderbook.org <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [user.email],
subject: template.subject,
body: template.message,
});
} catch (error) {
logger.error('Email sending error:', error);
}
try {
await subscribe({
email: user.email,
listName: 'purchased',
});
} catch (error) {
logger.error('Mailchimp error:', error);
The goal is to create Purchase
doc successfully.
After that we will investigate why purchase email was not sent by AWS SES.
Thanks.
Hi @tima101 ,
The purchase flow is successful this time by commenting out the lines as specified above!
I double checked that my second gmail address IS in the mailchimp MAILCHIMP_PURCHASED_LIST_ID.
let me know what I should test next.
thanks
@johnking Great. This means that Mailchimp works as expected but not email sending block of code.
Please comment out only this block of code to confirm our conclusion:
const template = await getEmailTemplate('purchased', {
userName: user.displayName,
bookTitle: book.name,
bookUrl: `https://builderbook.org/books/${book.slug}/introduction`,
});
try {
await sendEmail({
from: `Kelly from builderbook.org <${process.env.EMAIL_SUPPORT_FROM_ADDRESS}>`,
to: [user.email],
subject: template.subject,
body: template.message,
});
} catch (error) {
logger.error('Email sending error:', error);
}
If purchase works then problem is within above code block.
I may have found the problem, try fixing, replace purchased
with purchase
inside:
const template = await getEmailTemplate('purchased', {
I think your DB has 2 docs in EmailTemplates
collection, one has name welcome
and second has name purchase
(not purchased
). Thus error.
This means that third-party APIs work fine and you created/added proper env variables. Problem is in wrong name for email template. template
variable is likely undefined
in:
const template = await getEmailTemplate('purchased', {
userName: user.displayName,
bookTitle: book.name,
bookUrl: `https://builderbook.org/books/${book.slug}/introduction`,
});
You can confirm this by uncommenting all code and adding console.log(template);
under above code block. Then monitor output in your terminal.
If you confirm all above, please create pull request for fix. Thanks for running code and debugging, I could not run app since my env variable are on a different machine.
Yes, it works now. 👍
I will create a pull request soon.
thanks again.
@johnking Have you seen our SaaS boilerplate: https://github.com/async-labs/saas ?
If you happen to run/test/use our SaaS app, you are welcome to create pull requests in that repo as well.
Thanks.
hi @klyburke ,
thanks for your invitation, I will try your SaaS boilerplate later.
After deploying the app both in local env and production env (zeit), I found: a regular user could not open the book and read the chapter even though:
but it worked when I follow the instructions and code of chapter-8 book/8-end
I am using macPro, chrome.
thanks