Skip to content

PaysecureCommunity/Plugin-Shopify

Repository files navigation

PaySecure ShopifyPayments App - Remix [Javascript]

Reference: (https://shopify.dev/docs/apps/payments)

Notes:

  • mTLS configuration is not included in this template. This should be configured in your own infrastructure.
  • Any simulator in this template is not intended for a production payments app. In production, once a payment (or refund, capture, void) session has been started, the provider's processing steps should begin automatically, and should resolve/reject the session when complete.

Quick start

Prerequisites

  1. You must download and install Node.js if you don't already have it.
  2. You must create a Shopify partner account if you don’t have one.
  3. You must create a store for testing if you don't have one, either a development store or a Shopify Plus sandbox store.

App Setup

  1. You must Create an app manually in the Partners Dashboard
  2. Disable embedded in the Partners Dashboard
  3. Create an offsite payments app extension for your app. (https://shopify.dev/docs/apps/build/payments/offsite/use-the-cli)
  4. Replace App Name and API Client ID in the [shopify.app.toml]
  5. Run yarn shopify app config push to update your config with Shopify.

Setup

If you used the CLI to create the template, you can skip this section.

Using yarn:

yarn install

Using npm:

npm install

Using pnpm:

pnpm install

Local Development

Using yarn:

yarn dev

Using npm:

npm run dev

Using pnpm:

pnpm run dev

Before beginning development, set up your payments app extension. You can define a consitent tunnel for Shopify CLI to use with the --tunnel flag.

Local development is powered by the Shopify CLI. It logs into your partners account, connects to an app, provides environment variables, updates remote config, creates a tunnel and provides commands to generate extensions.

Press P to open a page to install your app.

App Extension

  1. Return to your payments app extension to begin filling it in.
  2. Set the payment and refund session URLs to the url hosted by dev.
  3. Create a version.
  4. Submit your extension for review.
  5. Once approved, release the new version.
  6. Now, you should be able to open the preview and set up your app through the configuration page.

Note: You may have to uninstall and reinstall the app from your store if the configuration page raises an error like "Payments App is not installed on this shop".

Authenticating and querying data

To authenticate and query data you can use the shopify const that is exported from /app/shopify.server.js:

export async function loader({ request }) {
  const { admin } = await shopify.authenticate.admin(request);

  const response = await admin.graphql(`
    {
      products(first: 25) {
        nodes {
          title
          description
        }
      }
    }`);

  const {
    data: {
      products: { nodes },
    },
  } = await response.json();

  return json(nodes);
}

## Deployment

### Application Storage

This template uses [Prisma](https://www.prisma.io/) to store session data, by default using an [SQLite](https://www.sqlite.org/index.html) database.
The database is defined as a Prisma schema in `prisma/schema.prisma`.

This use of SQLite works in production if your app runs as a single instance.
The database that works best for you depends on the data your app needs and how it is queried.
You can run your database of choice on a server yourself or host it with a SaaS company.
Here’s a short list of databases providers that provide a free tier to get started:

| Database   | Type             | Hosters                                                                                                                                                                                                                               |
| ---------- | ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| MySQL      | SQL              | [Digital Ocean](https://www.digitalocean.com/try/managed-databases-mysql), [Planet Scale](https://planetscale.com/), [Amazon Aurora](https://aws.amazon.com/rds/aurora/), [Google Cloud SQL](https://cloud.google.com/sql/docs/mysql) |
| PostgreSQL | SQL              | [Digital Ocean](https://www.digitalocean.com/try/managed-databases-postgresql), [Amazon Aurora](https://aws.amazon.com/rds/aurora/), [Google Cloud SQL](https://cloud.google.com/sql/docs/postgres)                                   |
| Redis      | Key-value        | [Digital Ocean](https://www.digitalocean.com/try/managed-databases-redis), [Amazon MemoryDB](https://aws.amazon.com/memorydb/)                                                                                                        |
| MongoDB    | NoSQL / Document | [Digital Ocean](https://www.digitalocean.com/try/managed-databases-mongodb), [MongoDB Atlas](https://www.mongodb.com/atlas/database)                                                                                                  |

To use one of these, you can use a different [datasource provider](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#datasource) in your `schema.prisma` file, or a different [SessionStorage adapter package](https://github.com/Shopify/shopify-api-js/tree/main/docs/guides/session-storage.md).

### Build

Remix handles building the app for you, by running the command below with the package manager of your choice:

Using yarn:

```shell
yarn build

Using npm:

npm run build

Using pnpm:

pnpm run build

Hosting

When you're ready to set up your app in production, you can follow our deployment documentation to host your app on a cloud provider like Heroku or Fly.io.

When you reach the step for setting up environment variables, you also need to set the variable NODE_ENV=production.

Gotchas / Troubleshooting

Database tables don't exist

If you run the app right after creating it, you'll get this error:

The table `main.Session` does not exist in the current database.

This will happen when the Prisma database hasn't been created. You can solve this by running the setup script in your app.

Navigating to other pages breaks

In Remix apps, you can navigate to a different page either by adding an <a> tag, or using the <Link> component from @remix-run/react.

In Shopify Remix apps you should avoid using <a>. Use <Link> from @remix-run/react instead. This ensures that your user remains authenticated.

OAuth goes into a loop when I change my app's scopes

If you change your app's scopes and notice that authentication goes into a loop and fails with a message from Shopify that it tried too many times, you might have forgotten to update your scopes with Shopify. To do that, you can run the config push CLI command.

Using yarn:

yarn shopify app config push

Using npm:

npm run shopify app config push

Using pnpm:

pnpm run shopify app config push

Tech Stack

This template uses Remix. The following Shopify tools are also included to ease app development:

  • Shopify App Remix provides authentication and methods for interacting with Shopify APIs.
  • Polaris React is a powerful design system and component library that helps developers build high quality, consistent experiences for Shopify merchants.
  • Polaris: Design system that enables apps to create Shopify-like experiences

Note: This template runs on JavaScript, but it's fully set up for TypeScript. If you want to create your routes using TypeScript, we recommend removing the noImplicitAny config from tsconfig.json

Resources

Releases

No releases published

Packages

 
 
 

Contributors