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

Problem with main repo app: book purchase #87

Closed
johnking opened this issue Aug 19, 2018 · 12 comments
Closed

Problem with main repo app: book purchase #87

johnking opened this issue Aug 19, 2018 · 12 comments
Assignees

Comments

@johnking
Copy link
Contributor

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:

  1. it shows the book on the list of 'Your books' after going through the purchasing procedure.

screen shot 2018-08-19 at 18 12 12

  1. After trying open it, it show the TOC, and big blue 'Buy button'
    screen shot 2018-08-19 at 18 13 53

  1. but it worked when I follow the instructions and code of chapter-8 book/8-end

  2. I am using macPro, chrome.

thanks

@klyburke
Copy link
Member

klyburke commented Aug 19, 2018

@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:

  • a Purchase document with proper userId and bookId parameters
  • a parameter purchasedBookIds in the User document with proper value (id of purchased book)

Do you see these data?

@klyburke klyburke self-assigned this Aug 19, 2018
@klyburke klyburke changed the title After purchasing a book, the book is still in lock mode Problem with deployed app: book purchase Aug 20, 2018
@johnking
Copy link
Contributor Author

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

  1. the ROOT_URL
  2. all kinds of env variables

-John

@klyburke klyburke changed the title Problem with deployed app: book purchase Problem with main repo app: book purchase Aug 20, 2018
@klyburke
Copy link
Member

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 proper userId and bookId parameters
  • a parameter purchasedBookIds in the User document with proper value (id of purchased book)

@johnking
Copy link
Contributor Author

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

screen shot 2018-08-20 at 09 46 49

  • 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

@tima101
Copy link
Member

tima101 commented Aug 20, 2018

@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.

@johnking
Copy link
Contributor Author

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.

screen shot 2018-08-20 at 12 03 41

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.

@tima101
Copy link
Member

tima101 commented Aug 20, 2018

@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.

@johnking
Copy link
Contributor Author

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

@tima101
Copy link
Member

tima101 commented Aug 20, 2018

@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.

@johnking
Copy link
Contributor Author

Yes, it works now. 👍

I will create a pull request soon.

thanks again.

johnking added a commit to johnking/builderbook that referenced this issue Aug 20, 2018
based on: async-labs#87, the correct email template name should be: 'purchase' instead of 'purchased'
@klyburke
Copy link
Member

@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.

@johnking
Copy link
Contributor Author

hi @klyburke ,

thanks for your invitation, I will try your SaaS boilerplate later.

ninjadevtrack pushed a commit to ninjadevtrack/builderbook that referenced this issue Dec 24, 2019
based on: async-labs/builderbook#87, the correct email template name should be: 'purchase' instead of 'purchased'
weshatleyfl pushed a commit to weshatleyfl/react-build-block that referenced this issue Apr 21, 2023
based on: async-labs/builderbook#87, the correct email template name should be: 'purchase' instead of 'purchased'
bruce691 pushed a commit to bruce691/builderbook that referenced this issue May 22, 2023
based on: async-labs/builderbook#87, the correct email template name should be: 'purchase' instead of 'purchased'
weshatleyfl pushed a commit to weshatleyfl/react-build-block that referenced this issue Jun 12, 2023
based on: async-labs/builderbook#87, the correct email template name should be: 'purchase' instead of 'purchased'
weshatleyfl pushed a commit to weshatleyfl/react-build-block that referenced this issue Jun 12, 2023
based on: async-labs/builderbook#87, the correct email template name should be: 'purchase' instead of 'purchased'
dmytrokabanets318 pushed a commit to dmytrokabanets318/builderbook that referenced this issue Aug 6, 2024
based on: async-labs/builderbook#87, the correct email template name should be: 'purchase' instead of 'purchased'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants