19 | Swapping to Development environment will display more detailed information about the error that occurred.
20 |
21 |
22 | Development environment should not be enabled in deployed applications, as it can result in sensitive information from exceptions being displayed to end users. For local debugging, development environment can be enabled by setting the ASPNETCORE_ENVIRONMENT environment variable to Development, and restarting the application.
23 |
21 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/.env.example:
--------------------------------------------------------------------------------
1 | # Must match the values found in the corresponding production or sandbox environment
2 | SQUARE_ACCESS_TOKEN=your-access-token
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "env": {
3 | "browser": true,
4 | "es6": true,
5 | "node": true
6 | },
7 | "extends": "eslint:recommended",
8 | "globals": {
9 | "Atomics": "readonly",
10 | "SharedArrayBuffer": "readonly"
11 | },
12 | "parserOptions": {
13 | "ecmaVersion": 2018,
14 | "sourceType": "module"
15 | },
16 | "rules": {
17 | // enable additional rules
18 | "indent": ["error", 2],
19 | "linebreak-style": ["error", "unix"],
20 | "quotes": ["error", "double"],
21 | "semi": ["error", "always"],
22 | "keyword-spacing":["error", { "before": true }],
23 | "object-curly-spacing": ["error","always"],
24 | "comma-spacing":["error",{"before":false,"after":true}],
25 | "no-console": ["error"],
26 | "no-unused-vars": ["warn"],
27 | "prefer-const": ["warn", {
28 | "destructuring": "any",
29 | "ignoreReadBeforeAssign": false
30 | }]
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .vscode
3 | .env
4 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/bin/images/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_invoices/bin/images/screenshot-1.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/bin/images/screenshot-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_invoices/bin/images/screenshot-2.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/bin/images/screenshot-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_invoices/bin/images/screenshot-3.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/public/README.md:
--------------------------------------------------------------------------------
1 | # Public
2 |
3 | We keep our publicly available files in this directory. This directory contains on sub-directory `stylesheets`.
4 |
5 |
6 | ## Stylesheets
7 |
8 | This directory contains all of the client side css styling for this demo application. The rendered HTML loads these files as needed via the link tag.
9 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/routes/README.md:
--------------------------------------------------------------------------------
1 | # Routes Directory
2 |
3 | Routes contains the [ExpressJs routes](https://expressjs.com/en/guide/routing.html) used to match the the requests the server receives.
4 |
5 | ## index.js
6 |
7 | The entry point that connects to all the other routes, it matches to the base of the url request.
8 | This is also the file that serves up the home page by rendering index.pug and display a list of customers.
9 |
10 | ## management.js
11 |
12 | This file matches any requests with `/management/*` in the base of the relative path of the url.
13 | It serves up the invoice management page for a selected customer by providing interface to create invoic and
14 | display a list of invoices.
15 |
16 | ## invoice.js
17 |
18 | This file matches any requests with `/invoice/*` in the base of the relative path of the url.
19 | It serves up all the invoice workflow by taking POST data from client and renders the page for
20 | an invoice.
21 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/util/README.md:
--------------------------------------------------------------------------------
1 | # Util
2 |
3 |
4 | Here we store files that are useful to define, either because they are widely used throughout the project or have a very verbose definition. In the case of `square-client.js`, it is widely used throughout the routes an it is simpler to define a square connect client once and require it into the necessary places in the app.
5 |
6 | square-client.js contains the instances of [SquareConnect APIs](https://developer.squareup.com/docs/) that are used throughout the project.
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/views/README.md:
--------------------------------------------------------------------------------
1 | # Views
2 |
3 | This directory contains the templates written in [PugJs](https://pugjs.org/api/getting-started.html). PugJs templates are rendered by [ExpressJs](https://expressjs.com/en/guide/using-template-engines.html)'s `render` function into HTML that is subsequently sent to the client's browser. Each `.pug` file is an individual view that the user can navigate through the app. When working with PugJs one needs to keep in mind that any javascript outside of a script block in the `.pug` file is run on the server side **before** it reaches to the client. To write client side javascript, write javascript within a script block or in a separate file and load it using script tags.
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/views/error.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2020 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | doctype html
16 | html
17 | head
18 | title="Error - Square Invoice Example"
19 | block styles
20 | link(rel='stylesheet', href='/stylesheets/main.css')
21 | body
22 | h1= status
23 | h2= message
24 | pre #{error}
25 |
26 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_invoices/views/layout.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2020 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | doctype html
16 | html
17 | head
18 | title="Square Invoice Example"
19 | block styles
20 | link(rel='stylesheet', href='/stylesheets/main.css')
21 | block scripts
22 | body
23 | block content
24 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/.env.example:
--------------------------------------------------------------------------------
1 | # Must match the values found in the corresponding production or sandbox environment
2 | SQ_APPLICATION_ID=your-application-id
3 | SQ_ACCESS_TOKEN=your-access-token
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "env": {
3 | "browser": true,
4 | "es6": true,
5 | "node": true
6 | },
7 | "extends": "eslint:recommended",
8 | "globals": {
9 | "Atomics": "readonly",
10 | "SharedArrayBuffer": "readonly"
11 | },
12 | "parserOptions": {
13 | "ecmaVersion": 2018,
14 | "sourceType": "module"
15 | },
16 | "rules": {
17 | // enable additional rules
18 | "indent": ["error", 2],
19 | "linebreak-style": ["error", "unix"],
20 | "quotes": ["error", "double"],
21 | "semi": ["error", "always"],
22 | "keyword-spacing":["error", { "before": true }],
23 | "object-curly-spacing": ["error","always"],
24 | "comma-spacing":["error",{"before":false,"after":true}],
25 | "no-console": ["error"],
26 | "no-unused-vars": ["warn"],
27 | "prefer-const": ["warn", {
28 | "destructuring": "any",
29 | "ignoreReadBeforeAssign": false
30 | }]
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .env
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-10.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-10.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-100.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-110.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-110.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-20.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-20.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-30.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-40.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-50.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-50.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-60.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-60.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-70.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-70.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-80.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-80.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-90.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/images/Order-Ahead-Diagram-90.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/autumn-soup@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/autumn-soup@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/bacon-burger@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/bacon-burger@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/chicken-sandwich@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/chicken-sandwich@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/egg-sunnyside-up-on-toast@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/egg-sunnyside-up-on-toast@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/grilled-steak@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/grilled-steak@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/italian-sandwich@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/italian-sandwich@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/meatballs@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/meatballs@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/mediterranean-yogurt-bowl@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/mediterranean-yogurt-bowl@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/oatmeal-with-fruit@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/oatmeal-with-fruit@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/pancakes-with-fruit@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/pancakes-with-fruit@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/salmon-with-zucchini@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/salmon-with-zucchini@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/bin/script/img/steak-tacos@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_orders-payments/bin/script/img/steak-tacos@2x.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "order-ahead-sample-app",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "NODE_ENV=production nodemon -e js,pug ./bin/www",
7 | "test": "NODE_ENV=sandbox nodemon -e js,pug ./bin/www",
8 | "seed": "NODE_ENV=sandbox node ./bin/script/seed-catalog.js generate",
9 | "clear": "NODE_ENV=sandbox node ./bin/script/seed-catalog.js clear",
10 | "help": "NODE_ENV=sandbox node ./bin/script/seed-catalog.js --help"
11 | },
12 | "dependencies": {
13 | "body-parser": "*",
14 | "cookie-parser": "*",
15 | "debug": "*",
16 | "dotenv": "^8.2.0",
17 | "eslint": "^6.1.0",
18 | "express": "*",
19 | "morgan": "*",
20 | "pug": "^3.0.2",
21 | "serve-favicon": "*",
22 | "square": "^25.1.0"
23 | },
24 | "devDependencies": {
25 | "nodemon": "^3.0.2"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/public/README.md:
--------------------------------------------------------------------------------
1 | # Public
2 |
3 | We keep our publicly available files in this directory. This directory contains two sub-directories `js` and `stylesheets`.
4 |
5 | ## Js
6 |
7 | This sub-directory contains all of the client side javascript for this demo application. The rendered HTML loads these files as needed via the script tag.
8 |
9 | ### Products-page.js
10 |
11 | This js file gets loaded by the index.pug template. This file controls the behavior of the item info modals.
12 |
13 | ### sq-payment-form.js
14 |
15 | This js file is an example how you create and use Square Payment Form to take credit/debit card payment.
16 |
17 | ## Stylesheets
18 |
19 | This directory contains all of the client side css styling for this demo application. The rendered HTML loads these files as needed via the link tag.
20 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/public/js/sq-card-pay.js:
--------------------------------------------------------------------------------
1 | window.CardPay = async function(fieldEl, buttonEl) {
2 | const payments = Square.payments(window.applicationId, window.locationId);
3 |
4 | // Create a card payment object and attach to page
5 | const card = await payments.card({
6 | style: {
7 | '.message-text.is-error': {
8 | color: '#BF0020'
9 | }
10 | }
11 | });
12 | await card.attach(fieldEl);
13 |
14 | async function eventHandler(event) {
15 | try {
16 | const result = await card.tokenize();
17 | if (result.status === 'OK') {
18 | // Use global method from sq-payment-flow.js
19 | window.createPayment(result.token);
20 | }
21 | } catch (e) {
22 | console.error(e);
23 | }
24 | };
25 |
26 | buttonEl.addEventListener('click', eventHandler);
27 | }
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/public/stylesheets/header.css:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2019 Square Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | /*
18 | HEADER
19 | */
20 |
21 | header {
22 | position: relative;
23 | text-align: center;
24 | padding: 40px 0;
25 | width: 100%;
26 | line-height: 32px;
27 | color: var(--business-name-color);
28 | }
29 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/public/stylesheets/sq-payment.css:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2021 Square Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 | #card-container {
17 | margin: 24px 0px;
18 | width: 100%;
19 | }
20 |
21 | #card-container:first-child {
22 | margin-left: 0;
23 | }
24 |
25 | #card-container:last-child {
26 | margin-right: 0;
27 | }
28 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/routes/README.md:
--------------------------------------------------------------------------------
1 | # Routes Directory
2 |
3 | Routes contains the [ExpressJs routes](https://expressjs.com/en/guide/routing.html) used to match the the requests the server receives.
4 |
5 | ## index.js
6 |
7 | The entry point that connects to all the other routes, it matches to the base of the url request.
8 | This is also the file that serves up the home page by rendering index.pug and take `create-order` request
9 | to kick off a checkout workflow.
10 |
11 | ## checkout.js
12 |
13 | This file matches any requests with `./checkout/*` in the base of the relative path of the url.
14 | It serves up all the checkout workflow by taking POST data from client and rendering the pages for
15 | each checkout steps.
16 |
17 | ## order-confirmation.js
18 |
19 | This file matches any requests with `./order-confirmation/` in the base of the relative path of the url.
20 | It serves up the confirmation page from a successful paid order and display the order's latest status.
21 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/util/README.md:
--------------------------------------------------------------------------------
1 | # Util
2 |
3 |
4 | Here we store files that are useful to define, either because they are widely used throughout the project or have a very verbose definition. In the case of `square-client.js`, it is widely used throughout the routes an it is simpler to define a square client once and require it into the necessary places in the app.
5 |
6 | square-client.js contains the instances of [Square APIs](https://developer.squareup.com/docs/) that are used throughout the project and also provide utilities to fetch a collection of related square data.
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/views/README.md:
--------------------------------------------------------------------------------
1 | # Views
2 |
3 | This directory contains the templates written in [PugJs](https://pugjs.org/api/getting-started.html). PugJs templates are rendered by [ExpressJs](https://expressjs.com/en/guide/using-template-engines.html)'s `render` function into HTML that is subsequently sent to the client's browser. Each `.pug` file is an individual view that the user can navigate through the app. When working with PugJs one needs to keep in mind that any javascript outside of a script block in the `.pug` file is run on the server side **before** it reaches to the client. To write client side javascript, write javascript within a script block or in a separate file and load it using script tags.
4 |
5 | ## Includes
6 |
7 | The `/includes` subdirectory contains pug files that can be `included` into other `.pug` files. Including `.pug` files into one another can be thought of as akin to component composition found in other front end frameworks. This allows us to write more modular templates that can be reused in different views.
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/views/error.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2019 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | doctype html
16 | html
17 | head
18 | title="Error - Order Ahead Example"
19 | block styles
20 | link(rel='stylesheet', href='/stylesheets/main.css')
21 | body
22 | div(class="cocoon")
23 | h1= status
24 | h2= message
25 | pre #{error}
26 |
27 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/views/includes/header.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2019 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | block append styles
16 | link(rel='stylesheet', href='/stylesheets/header.css')
17 | header
18 | div
19 | a(href="/") #{locationInfo.storeName.toUpperCase()}
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/views/includes/loyalty-panel.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2019 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | div(class="panel clearfix")
16 | if (!loyaltyRewardInfo.loyaltyAccountId)
17 | include ./attach-loyalty-account.pug
18 | else
19 | include ./redeem-loyalty-reward.pug
20 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_orders-payments/views/layout.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2019 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | doctype html
16 | html
17 | head
18 | title="Order Ahead Example"
19 | block styles
20 | link(rel='stylesheet', href='/stylesheets/main.css')
21 | block scripts
22 | body
23 | div(class="cocoon")
24 | include includes/header.pug
25 | block content
26 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/.env.example:
--------------------------------------------------------------------------------
1 | # Must match the values found in the corresponding production or sandbox environment
2 | SQ_APPLICATION_ID=your-application-id
3 | SQ_ACCESS_TOKEN=your-access-token
4 | SQ_LOCATION_ID=your-location-id
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 |
6 | # Runtime data
7 | pids
8 | *.pid
9 | *.seed
10 |
11 | # Directory for instrumented libs generated by jscoverage/JSCover
12 | lib-cov
13 |
14 | # Coverage directory used by tools like istanbul
15 | coverage
16 |
17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
18 | .grunt
19 |
20 | # node-waf configuration
21 | .lock-wscript
22 |
23 | # Compiled binary addons (http://nodejs.org/api/addons.html)
24 | build/Release
25 |
26 | # Dependency directories
27 | node_modules
28 | jspm_packages
29 |
30 | # Optional npm cache directory
31 | .npm
32 |
33 | # Optional REPL history
34 | .node_repl_history
35 |
36 | # Environment credentials
37 | .env
38 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/.well-known/apple-developer-merchantid-domain-association:
--------------------------------------------------------------------------------
1 | THIS IS A PLACE HOLDER FOR APPLE PAY DOMAIN VERIFICATION
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/PaymentFormExampleNode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_payment/PaymentFormExampleNode.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "node-payment",
3 | "version": "0.0.0",
4 | "private": true,
5 | "scripts": {
6 | "start": "NODE_ENV=production node ./bin/www",
7 | "test": "NODE_ENV=sandbox node ./bin/www"
8 | },
9 | "dependencies": {
10 | "body-parser": "*",
11 | "cookie-parser": "*",
12 | "debug": "*",
13 | "dotenv": "^8.2.0",
14 | "express": "*",
15 | "morgan": "*",
16 | "pug": "^3.0.2",
17 | "square": "^33.0.0"
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/public/js/sq-apple-pay.js:
--------------------------------------------------------------------------------
1 | async function ApplePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 |
7 | let applePay;
8 | try {
9 | applePay = await window.payments.applePay(paymentRequest);
10 | } catch (e) {
11 | console.error(e)
12 | return;
13 | }
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await applePay.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/public/js/sq-card-pay.js:
--------------------------------------------------------------------------------
1 | async function CardPay(fieldEl, buttonEl) {
2 | // Create a card payment object and attach to page
3 | const card = await window.payments.card({
4 | style: {
5 | '.input-container.is-focus': {
6 | borderColor: '#006AFF'
7 | },
8 | '.message-text.is-error': {
9 | color: '#BF0020'
10 | }
11 | }
12 | });
13 | await card.attach(fieldEl);
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await card.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/public/js/sq-google-pay.js:
--------------------------------------------------------------------------------
1 | async function GooglePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 | const googlePay = await payments.googlePay(paymentRequest);
7 | await googlePay.attach(buttonEl);
8 |
9 | async function eventHandler(event) {
10 | // Clear any existing messages
11 | window.paymentFlowMessageEl.innerText = '';
12 |
13 | try {
14 | const result = await googlePay.tokenize();
15 | if (result.status === 'OK') {
16 | // Use global method from sq-payment-flow.js
17 | window.createPayment(result.token);
18 | }
19 | } catch (e) {
20 | if (e.message) {
21 | window.showError(`Error: ${e.message}`);
22 | } else {
23 | window.showError('Something went wrong');
24 | }
25 | }
26 | }
27 |
28 | buttonEl.addEventListener('click', eventHandler);
29 | }
30 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/util/square-client.js:
--------------------------------------------------------------------------------
1 | const { Client } = require('square');
2 |
3 | require('dotenv').config()
4 |
5 | // Square client config
6 | const config = {
7 | environment: process.env.NODE_ENV,
8 | accessToken: process.env.SQ_ACCESS_TOKEN,
9 | userAgentDetail: "sample_app_node_payment" // Remove or replace this detail when building your own app
10 | }
11 |
12 | // Configure instance of Square client
13 | const defaultClient = new Client(config)
14 |
15 | module.exports = defaultClient
16 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/views/error.pug:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | h1= message
5 | h2= error.status
6 | pre #{error.stack}
7 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_payment/views/layout.pug:
--------------------------------------------------------------------------------
1 | doctype html
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/stylesheets/sq-payment.css')
6 | link(rel='stylesheet', href='/stylesheets/style.css')
7 | body
8 | block content
9 |
10 | script(type="text/javascript" src="/js/sq-payment-flow.js")
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/.env.example:
--------------------------------------------------------------------------------
1 | # Must match the values found in the corresponding production or sandbox environment
2 | SQUARE_ACCESS_TOKEN=YOUR_ACCESS_TOKEN
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | "env": {
3 | "browser": true,
4 | "es6": true,
5 | "node": true
6 | },
7 | "extends": "eslint:recommended",
8 | "globals": {
9 | "Atomics": "readonly",
10 | "SharedArrayBuffer": "readonly"
11 | },
12 | "parserOptions": {
13 | "ecmaVersion": 2018,
14 | "sourceType": "module"
15 | },
16 | "rules": {
17 | // enable additional rules
18 | "indent": ["error", 2],
19 | "linebreak-style": ["error", "unix"],
20 | "quotes": ["error", "double"],
21 | "semi": ["error", "always"],
22 | "keyword-spacing":["error", { "before": true }],
23 | "object-curly-spacing": ["error","always"],
24 | "comma-spacing":["error",{"before":false,"after":true}],
25 | "no-console": ["error"],
26 | "no-unused-vars": ["warn"],
27 | "prefer-const": ["warn", {
28 | "destructuring": "any",
29 | "ignoreReadBeforeAssign": false
30 | }]
31 | }
32 | };
33 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .vscode
3 | .env
4 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/bin/images/screenshot-1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_subscription/bin/images/screenshot-1.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/bin/images/screenshot-2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_subscription/bin/images/screenshot-2.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/bin/images/screenshot-3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_subscription/bin/images/screenshot-3.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/bin/images/screenshot-4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_subscription/bin/images/screenshot-4.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/bin/images/screenshot-5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_subscription/bin/images/screenshot-5.png
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/models/README.md:
--------------------------------------------------------------------------------
1 | # Models
2 |
3 | This directory contains classes that abstracts the data for the templates found in the [Views](../views/README.md) directory
4 |
5 | ## subscription-details-info.js
6 |
7 | Defines a class that translate subscription plan details and current subscription status into a human readable model.
8 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/public/README.md:
--------------------------------------------------------------------------------
1 | # Public
2 |
3 | We keep our publicly available files in this directory. This directory contains on sub-directory `stylesheets`.
4 |
5 |
6 | ## Stylesheets
7 |
8 | This directory contains all of the client side css styling for this demo application. The rendered HTML loads these files as needed via the link tag.
9 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/public/stylesheets/subscription.css:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright 2020 Square Inc.
3 |
4 | Licensed under the Apache License, Version 2.0 (the "License");
5 | you may not use this file except in compliance with the License.
6 | You may obtain a copy of the License at
7 |
8 | http://www.apache.org/licenses/LICENSE-2.0
9 |
10 | Unless required by applicable law or agreed to in writing, software
11 | distributed under the License is distributed on an "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | See the License for the specific language governing permissions and
14 | limitations under the License.
15 | */
16 |
17 | .phase-label {
18 | font-weight: 500;
19 | font-size: 12px;
20 | text-transform: uppercase;
21 | }
22 |
23 | .subscribe-button {
24 | background: #006BE6;
25 | color: #FFFFFF;
26 | }
27 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/util/README.md:
--------------------------------------------------------------------------------
1 | # Util
2 |
3 |
4 | Here we store files that are useful to define, either because they are widely used throughout the project or have a very verbose definition. In the case of `square-client.js`, it is widely used throughout the routes an it is simpler to define a square client once and require it into the necessary places in the app.
5 |
6 | square-client.js contains the instances of [Square APIs](https://developer.squareup.com/docs/) that are used throughout the project.
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/views/README.md:
--------------------------------------------------------------------------------
1 | # Views
2 |
3 | This directory contains the templates written in [PugJs](https://pugjs.org/api/getting-started.html). PugJs templates are rendered by [ExpressJs](https://expressjs.com/en/guide/using-template-engines.html)'s `render` function into HTML that is subsequently sent to the client's browser. Each `.pug` file is an individual view that the user can navigate through the app. When working with PugJs one needs to keep in mind that any javascript outside of a script block in the `.pug` file is run on the server side **before** it reaches to the client. To write client side javascript, write javascript within a script block or in a separate file and load it using script tags.
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/views/error.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2020 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | doctype html
16 | html
17 | head
18 | title="Error - Square Subscriptions API Example"
19 | block styles
20 | link(rel='stylesheet', href='/stylesheets/main.css')
21 | body
22 | h1= status
23 | h2= message
24 | pre #{error}
25 |
26 |
--------------------------------------------------------------------------------
/connect-examples/v2/node_subscription/views/layout.pug:
--------------------------------------------------------------------------------
1 | //- Copyright 2020 Square Inc.
2 |
3 | //- Licensed under the Apache License, Version 2.0 (the "License");
4 | //- you may not use this file except in compliance with the License.
5 | //- You may obtain a copy of the License at
6 |
7 | //- http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | //- Unless required by applicable law or agreed to in writing, software
10 | //- distributed under the License is distributed on an "AS IS" BASIS,
11 | //- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | //- See the License for the specific language governing permissions and
13 | //- limitations under the License.
14 |
15 | doctype html
16 | html
17 | head
18 | title="Square Subscriptions API Example"
19 | block styles
20 | link(rel='stylesheet', href='/stylesheets/main.css')
21 | block scripts
22 | body
23 | block content
24 |
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/.env.example:
--------------------------------------------------------------------------------
1 | # Acceptable values are sandbox or production
2 | ENVIRONMENT=
3 |
4 | # Must match the values found in the corresponding production or sandbox environment
5 | SQUARE_APPLICATION_ID=your-application-id
6 | SQUARE_ACCESS_TOKEN=your-access-token
7 | SQUARE_LOCATION_ID=your-location-id
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/.gitignore:
--------------------------------------------------------------------------------
1 | .env
2 |
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/.well-known/apple-developer-merchantid-domain-association:
--------------------------------------------------------------------------------
1 | THIS IS PLACEHOLDER FOR APPLE PAY DOMAIN VERIFICATION FILE
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "require": {
3 | "square/square": "18.0.0.20220420",
4 | "vlucas/phpdotenv": "^3.3",
5 | "ramsey/uuid": "*"
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/public/js/sq-apple-pay.js:
--------------------------------------------------------------------------------
1 | async function ApplePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 |
7 | let applePay;
8 | try {
9 | applePay = await window.payments.applePay(paymentRequest);
10 | } catch (e) {
11 | console.error(e)
12 | return;
13 | }
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await applePay.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/public/js/sq-card-pay.js:
--------------------------------------------------------------------------------
1 | async function CardPay(fieldEl, buttonEl) {
2 | // Create a card payment object and attach to page
3 | const card = await window.payments.card({
4 | style: {
5 | '.input-container.is-focus': {
6 | borderColor: '#006AFF'
7 | },
8 | '.message-text.is-error': {
9 | color: '#BF0020'
10 | }
11 | }
12 | });
13 | await card.attach(fieldEl);
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await card.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/php_payment/public/js/sq-google-pay.js:
--------------------------------------------------------------------------------
1 | async function GooglePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 | const googlePay = await payments.googlePay(paymentRequest);
7 | await googlePay.attach(buttonEl);
8 |
9 | async function eventHandler(event) {
10 | // Clear any existing messages
11 | window.paymentFlowMessageEl.innerText = '';
12 |
13 | try {
14 | const result = await googlePay.tokenize();
15 | if (result.status === 'OK') {
16 | // Use global method from sq-payment-flow.js
17 | window.createPayment(result.token);
18 | }
19 | } catch (e) {
20 | if (e.message) {
21 | window.showError(`Error: ${e.message}`);
22 | } else {
23 | window.showError('Something went wrong');
24 | }
25 | }
26 | }
27 |
28 | buttonEl.addEventListener('click', eventHandler);
29 | }
30 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/.gitignore:
--------------------------------------------------------------------------------
1 | config.ini
2 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/.well-known/apple-developer-merchantid-domain-association:
--------------------------------------------------------------------------------
1 | REPLACE_ME
2 | (Get this file from the apple pay section tab of your application dashboard)
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/PaymentFormExamplePython.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/python_payment/PaymentFormExamplePython.png
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/config.ini.example:
--------------------------------------------------------------------------------
1 | [DEFAULT]
2 | # Acceptable values are sandbox or production
3 | environment =
4 |
5 | [PRODUCTION]
6 | square_application_id = production_application_id
7 | square_access_token = production_access_token
8 | square_location_id = production_location_id
9 |
10 | [SANDBOX]
11 | square_application_id = sandbox_application_id
12 | square_access_token = sandbox_access_token
13 | square_location_id = sandbox_location_id
14 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/requirements.txt:
--------------------------------------------------------------------------------
1 | squareup==22.0.0.20220921
2 | configparser
3 | fastapi
4 | uvicorn
5 | aiofiles
6 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/static/js/sq-apple-pay.js:
--------------------------------------------------------------------------------
1 | async function ApplePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 |
7 | let applePay;
8 | try {
9 | applePay = await window.payments.applePay(paymentRequest);
10 | } catch (e) {
11 | console.error(e)
12 | return;
13 | }
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await applePay.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/static/js/sq-card-pay.js:
--------------------------------------------------------------------------------
1 | async function CardPay(fieldEl, buttonEl) {
2 | // Create a card payment object and attach to page
3 | const card = await window.payments.card({
4 | style: {
5 | '.input-container.is-focus': {
6 | borderColor: '#006AFF'
7 | },
8 | '.message-text.is-error': {
9 | color: '#BF0020'
10 | }
11 | }
12 | });
13 | await card.attach(fieldEl);
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await card.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/python_payment/static/js/sq-google-pay.js:
--------------------------------------------------------------------------------
1 | async function GooglePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 | const googlePay = await payments.googlePay(paymentRequest);
7 | await googlePay.attach(buttonEl);
8 |
9 | async function eventHandler(event) {
10 | // Clear any existing messages
11 | window.paymentFlowMessageEl.innerText = '';
12 |
13 | try {
14 | const result = await googlePay.tokenize();
15 | if (result.status === 'OK') {
16 | // Use global method from sq-payment-flow.js
17 | window.createPayment(result.token);
18 | }
19 | } catch (e) {
20 | if (e.message) {
21 | window.showError(`Error: ${e.message}`);
22 | } else {
23 | window.showError('Something went wrong');
24 | }
25 | }
26 | }
27 |
28 | buttonEl.addEventListener('click', eventHandler);
29 | }
30 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/.env.example:
--------------------------------------------------------------------------------
1 | # Acceptable values are sandbox or production
2 | ENVIRONMENT=sandbox
3 |
4 | # Must match the values found in the corresponding production or sandbox environment
5 | SQUARE_APPLICATION_ID=your-application-id
6 | SQUARE_ACCESS_TOKEN=your-access-token
7 | SQUARE_LOCATION_ID=your-location-id
8 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore the default SQLite database.
11 | /db/*.sqlite3
12 | /db/*.sqlite3-journal
13 |
14 | # Ignore all logfiles and tempfiles.
15 | /log/*
16 | !/log/.keep
17 | tmp/
18 | .byebug_history
19 |
20 | # Ignore environment files
21 | .env
22 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/.ruby-version:
--------------------------------------------------------------------------------
1 | ruby-2.7.2
2 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/Gemfile:
--------------------------------------------------------------------------------
1 | source 'https://rubygems.org'
2 |
3 | ruby "2.7.2"
4 |
5 | # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
6 | gem 'rails', '~> 6.1.0'
7 |
8 | # Use SCSS for stylesheets
9 | gem 'sass-rails', '~> 6.0'
10 | # Use Uglifier as compressor for JavaScript assets
11 | gem 'uglifier', '>= 1.3.0'
12 | # See https://github.com/rails/execjs#readme for more supported runtimes
13 | # gem 'therubyracer', platforms: :ruby
14 |
15 | # Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
16 | gem 'turbolinks'
17 |
18 | gem 'square.rb', '~> 22.0.0.20220817 '
19 |
20 | gem 'rails_12factor', group: :production
21 |
22 | group :development, :test do
23 | # Call 'byebug' anywhere in the code to stop execution and get a debugger console
24 | gem 'byebug'
25 | gem 'dotenv-rails'
26 | end
27 |
28 | group :development do
29 | # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
30 | gem 'spring'
31 | end
32 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/Procfile:
--------------------------------------------------------------------------------
1 | email: bundle exec mailcatcher --foreground
2 | web: bundle exec rails s
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require File.expand_path('../config/application', __FILE__)
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/apple-developer-merchantid-domain-association:
--------------------------------------------------------------------------------
1 | CHANGE-ME
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link application.css
2 | //= link application.js
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/app/assets/images/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/javascripts/application.js:
--------------------------------------------------------------------------------
1 | // This is a manifest file that'll be compiled into application.js, which will include all the files
2 | // listed below.
3 | //
4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5 | // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6 | //
7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8 | // compiled file.
9 | //
10 | // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11 | // about supported directives.
12 | //
13 | //= require turbolinks
14 |
15 | //= require sq-ach.js
16 | //= require sq-apple-pay.js
17 | //= require sq-card-pay.js
18 | //= require sq-google-pay.js
19 | //= require sq-payment-flow.js
20 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/javascripts/sq-apple-pay.js:
--------------------------------------------------------------------------------
1 | async function ApplePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 |
7 | let applePay;
8 | try {
9 | applePay = await window.payments.applePay(paymentRequest);
10 | } catch (e) {
11 | console.error(e)
12 | return;
13 | }
14 |
15 | async function eventHandler(event) {
16 | // Clear any existing messages
17 | window.paymentFlowMessageEl.innerText = '';
18 |
19 | try {
20 | const result = await applePay.tokenize();
21 | if (result.status === 'OK') {
22 | // Use global method from sq-payment-flow.js
23 | window.createPayment(result.token);
24 | }
25 | } catch (e) {
26 | if (e.message) {
27 | window.showError(`Error: ${e.message}`);
28 | } else {
29 | window.showError('Something went wrong');
30 | }
31 | }
32 | }
33 |
34 | buttonEl.addEventListener('click', eventHandler);
35 | }
36 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/javascripts/sq-google-pay.js:
--------------------------------------------------------------------------------
1 | async function GooglePay(buttonEl) {
2 | const paymentRequest = window.payments.paymentRequest(
3 | // Use global method from sq-payment-flow.js
4 | window.getPaymentRequest()
5 | );
6 | const googlePay = await payments.googlePay(paymentRequest);
7 | await googlePay.attach(buttonEl);
8 |
9 | async function eventHandler(event) {
10 | // Clear any existing messages
11 | window.paymentFlowMessageEl.innerText = '';
12 |
13 | try {
14 | const result = await googlePay.tokenize();
15 | if (result.status === 'OK') {
16 | // Use global method from sq-payment-flow.js
17 | window.createPayment(result.token);
18 | }
19 | } catch (e) {
20 | if (e.message) {
21 | window.showError(`Error: ${e.message}`);
22 | } else {
23 | window.showError('Something went wrong');
24 | }
25 | }
26 | }
27 |
28 | buttonEl.addEventListener('click', eventHandler);
29 | }
30 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/assets/stylesheets/application.css:
--------------------------------------------------------------------------------
1 | /*
2 | * This is a manifest file that'll be compiled into application.css, which will include all the files
3 | * listed below.
4 | *
5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6 | * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7 | *
8 | * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9 | * compiled file so the styles you add here take precedence over styles defined in any styles
10 | * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11 | * file per style scope.
12 | *
13 | *= require style.css
14 | *= require sq-payment.css
15 | *= require_self
16 | */
17 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/controllers/apple_controller.rb:
--------------------------------------------------------------------------------
1 | class AppleController < ApplicationController
2 | def domain_association
3 | send_file 'app/assets/apple-developer-merchantid-domain-association'
4 | end
5 | end
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 | # Prevent CSRF attacks by raising an exception.
3 | # For APIs, you may want to use :null_session instead.
4 | protect_from_forgery with: :exception
5 | end
6 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/controllers/welcome_controller.rb:
--------------------------------------------------------------------------------
1 | class WelcomeController < ApplicationController
2 | include SquareApiHelper
3 |
4 | def index
5 | location = square_api_client
6 | .locations
7 | .retrieve_location(location_id: ENV['SQUARE_LOCATION_ID'])
8 | .data[:location]
9 |
10 | @country = location[:country]
11 | @currency = location[:currency]
12 | @idempotencyKey = SecureRandom.uuid
13 |
14 | render layout: 'index'
15 | end
16 | end
17 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/helpers/square_api_helper.rb:
--------------------------------------------------------------------------------
1 | module SquareApiHelper
2 | def square_api_client
3 | # Create an instance of the API Client and initialize it with the credentials
4 | # for the Square account whose assets you want to manage.
5 | @api_client ||= Square::Client.new(
6 | access_token: Rails.application.secrets.square_access_token,
7 | environment: ENV['ENVIRONMENT'],
8 | user_agent_detail: "sample_app_rails_payment" # Remove or replace this detail when building your own app
9 | )
10 | end
11 | end
12 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/mailers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/app/mailers/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/app/models/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/app/models/concerns/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/app/views/layouts/index.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | RailsPayment
5 | <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
6 | <%= csrf_meta_tags %>
7 |
11 | <%= stylesheet_link_tag 'application', 'data-turbolinks-track' => true %>
12 |
13 |
14 |
15 | <%= yield %>
16 |
17 |
18 | <% if ENV['ENVIRONMENT'] == 'production' %>
19 | <%= javascript_include_tag 'https://web.squarecdn.com/v1/square.js', 'application', 'data-turbolinks-track' => true%>
20 | <% else %>
21 | <%= javascript_include_tag 'https://sandbox.web.squarecdn.com/v1/square.js', 'application', 'data-turbolinks-track' => true%>
22 | <% end %>
23 |
24 |
25 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/bin/bundle:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3 | load Gem.bin_path('bundler', 'bundle')
4 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/bin/rails:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | APP_PATH = File.expand_path('../../config/application', __FILE__)
8 | require_relative '../config/boot'
9 | require 'rails/commands'
10 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/bin/rake:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | begin
3 | load File.expand_path('../spring', __FILE__)
4 | rescue LoadError => e
5 | raise unless e.message.include?('spring')
6 | end
7 | require_relative '../config/boot'
8 | require 'rake'
9 | Rake.application.run
10 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/bin/setup:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 | require 'pathname'
3 |
4 | # path to your application root.
5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6 |
7 | Dir.chdir APP_ROOT do
8 | # This script is a starting point to setup your application.
9 | # Add necessary setup steps to this file:
10 |
11 | puts "== Installing dependencies =="
12 | system "gem install bundler --conservative"
13 | system "bundle check || bundle install"
14 |
15 | # puts "\n== Copying sample files =="
16 | # unless File.exist?("config/database.yml")
17 | # system "cp config/database.yml.sample config/database.yml"
18 | # end
19 |
20 | puts "\n== Preparing database =="
21 | system "bin/rake db:setup"
22 |
23 | puts "\n== Removing old logs and tempfiles =="
24 | system "rm -f log/*"
25 | system "rm -rf tmp/cache"
26 |
27 | puts "\n== Restarting application server =="
28 | system "touch tmp/restart.txt"
29 | end
30 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/bin/spring:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby
2 |
3 | # This file loads spring without using Bundler, in order to be fast.
4 | # It gets overwritten when you run the `spring binstub` command.
5 |
6 | unless defined?(Spring)
7 | require 'rubygems'
8 | require 'bundler'
9 |
10 | if (match = Bundler.default_lockfile.read.match(/^GEM$.*?^ (?: )*spring \((.*?)\)$.*?^$/m))
11 | Gem.paths = { 'GEM_PATH' => [Bundler.bundle_path.to_s, *Gem.path].uniq.join(Gem.path_separator) }
12 | gem 'spring', match[1]
13 | require 'spring/binstub'
14 | end
15 | end
16 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config.ru:
--------------------------------------------------------------------------------
1 | # This file is used by Rack-based servers to start the application.
2 |
3 | require ::File.expand_path('../config/environment', __FILE__)
4 | run Rails.application
5 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/boot.rb:
--------------------------------------------------------------------------------
1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2 |
3 | require 'bundler/setup' # Set up gems listed in the Gemfile.
4 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/database.yml:
--------------------------------------------------------------------------------
1 | # SQLite version 3.x
2 | # gem install sqlite3
3 | #
4 | # Ensure the SQLite 3 gem is defined in your Gemfile
5 | # gem 'sqlite3'
6 | #
7 | default: &default
8 | adapter: sqlite3
9 | pool: 5
10 | timeout: 5000
11 |
12 | development:
13 | <<: *default
14 | database: db/development
15 |
16 | # Warning: The database defined as "test" will be erased and
17 | # re-generated from your development database when you run "rake".
18 | # Do not set this db to the same as development or production.
19 | test:
20 | <<: *default
21 | database: db/test
22 |
23 | production:
24 | <<: *default
25 | database: db/production
26 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/environment.rb:
--------------------------------------------------------------------------------
1 | # Load the Rails application.
2 | require File.expand_path('../application', __FILE__)
3 |
4 | # Initialize the Rails application.
5 | Rails.application.initialize!
6 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/assets.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Version of your assets, change this if you want to expire all your assets.
4 | Rails.application.config.assets.version = '1.0'
5 |
6 | # Add additional assets to the asset load path
7 | # Rails.application.config.assets.paths << Emoji.images_path
8 |
9 | # Precompile additional assets.
10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
11 | Rails.application.config.assets.precompile = ["manifest.js"]
12 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/backtrace_silencers.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
5 |
6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
7 | # Rails.backtrace_cleaner.remove_silencers!
8 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/cookies_serializer.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.action_dispatch.cookies_serializer = :json
4 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/filter_parameter_logging.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Configure sensitive parameters which will be filtered from the log file.
4 | Rails.application.config.filter_parameters += [:password]
5 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/inflections.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new inflection rules using the following format. Inflections
4 | # are locale specific, and you may define rules for as many different
5 | # locales as you wish. All of these examples are active by default:
6 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
7 | # inflect.plural /^(ox)$/i, '\1en'
8 | # inflect.singular /^(ox)en/i, '\1'
9 | # inflect.irregular 'person', 'people'
10 | # inflect.uncountable %w( fish sheep )
11 | # end
12 |
13 | # These inflection rules are supported but not enabled by default:
14 | # ActiveSupport::Inflector.inflections(:en) do |inflect|
15 | # inflect.acronym 'RESTful'
16 | # end
17 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/mime_types.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # Add new mime types for use in respond_to blocks:
4 | # Mime::Type.register "text/richtext", :rtf
5 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/session_store.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | Rails.application.config.session_store :cookie_store, key: '_rails_payment_session'
4 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/initializers/wrap_parameters.rb:
--------------------------------------------------------------------------------
1 | # Be sure to restart your server when you modify this file.
2 |
3 | # This file contains settings for ActionController::ParamsWrapper which
4 | # is enabled by default.
5 |
6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array.
7 | ActiveSupport.on_load(:action_controller) do
8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters)
9 | end
10 |
11 | # To enable root element in JSON for ActiveRecord objects.
12 | # ActiveSupport.on_load(:active_record) do
13 | # self.include_root_in_json = true
14 | # end
15 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/config/locales/en.yml:
--------------------------------------------------------------------------------
1 | # Files in the config/locales directory are used for internationalization
2 | # and are automatically loaded by Rails. If you want to use locales other
3 | # than English, add the necessary files in this directory.
4 | #
5 | # To use the locales, use `I18n.t`:
6 | #
7 | # I18n.t 'hello'
8 | #
9 | # In views, this is aliased to just `t`:
10 | #
11 | # <%= t('hello') %>
12 | #
13 | # To use a different locale, set it with `I18n.locale`:
14 | #
15 | # I18n.locale = :es
16 | #
17 | # This would use the information in config/locales/es.yml.
18 | #
19 | # To learn more, please read the Rails Internationalization guide
20 | # available at http://guides.rubyonrails.org/i18n.html.
21 |
22 | en:
23 | hello: "Hello world"
24 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/db/schema.rb:
--------------------------------------------------------------------------------
1 | # encoding: UTF-8
2 | # This file is auto-generated from the current state of the database. Instead
3 | # of editing this file, please use the migrations feature of Active Record to
4 | # incrementally modify your database, and then regenerate this schema definition.
5 | #
6 | # Note that this schema.rb definition is the authoritative source for your
7 | # database schema. If you need to create the application database on another
8 | # system, you should be using db:schema:load, not running all the migrations
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 | # you'll amass, the slower it'll run and the greater likelihood for issues).
11 | #
12 | # It's strongly recommended that you check this file into your version control system.
13 |
14 | ActiveRecord::Schema.define(version: 0) do
15 |
16 | end
17 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/db/seeds.rb:
--------------------------------------------------------------------------------
1 | # This file should contain all the record creation needed to seed the database with its default values.
2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
3 | #
4 | # Examples:
5 | #
6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
7 | # Mayor.create(name: 'Emanuel', city: cities.first)
8 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/lib/assets/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/lib/assets/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/lib/tasks/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/lib/tasks/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/log/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/log/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/public/favicon.ico
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/public/robots.txt:
--------------------------------------------------------------------------------
1 | # See http://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file
2 | #
3 | # To ban all spiders from the entire site uncomment the next two lines:
4 | # User-agent: *
5 | # Disallow: /
6 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/controllers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/test/controllers/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/controllers/payments_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class PaymentsControllerTest < ActionController::TestCase
4 | test "should post process" do
5 | post :process
6 | assert_response :success
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/controllers/welcome_controller_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class WelcomeControllerTest < ActionController::TestCase
4 | test "should get index" do
5 | get :index
6 | assert_response :success
7 | end
8 |
9 | end
10 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/fixtures/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/test/fixtures/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/helpers/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/test/helpers/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/integration/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/test/integration/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/models/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_payment/test/models/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_payment/test/test_helper.rb:
--------------------------------------------------------------------------------
1 | ENV['RAILS_ENV'] ||= 'test'
2 | require File.expand_path('../../config/environment', __FILE__)
3 | require 'rails/test_help'
4 |
5 | class ActiveSupport::TestCase
6 | # Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
7 | fixtures :all
8 |
9 | # Add more helper methods to be used by all tests here...
10 | end
11 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/.browserslistrc:
--------------------------------------------------------------------------------
1 | defaults
2 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/.env:
--------------------------------------------------------------------------------
1 | SQUARE_APPLICATION_ID=your-app-id
2 | SQUARE_APPLICATION_SECRET=your-app-secret
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/.gitattributes:
--------------------------------------------------------------------------------
1 | # See https://git-scm.com/docs/gitattributes for more about git attribute files.
2 |
3 |
4 | # Mark the yarn lockfile as having been generated.
5 | yarn.lock linguist-generated
6 |
7 | # Mark any vendored files as having been vendored.
8 | vendor/* linguist-vendored
9 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2 | #
3 | # If you find yourself ignoring temporary files generated by your text editor
4 | # or operating system, you probably want to add a global ignore instead:
5 | # git config --global core.excludesfile '~/.gitignore_global'
6 |
7 | # Ignore bundler config.
8 | /.bundle
9 |
10 | # Ignore all logfiles and tempfiles.
11 | /log/*
12 | /tmp/*
13 | !/log/.keep
14 | !/tmp/.keep
15 |
16 | # Ignore pidfiles, but keep the directory.
17 | /tmp/pids/*
18 | !/tmp/pids/
19 | !/tmp/pids/.keep
20 |
21 |
22 | /public/assets
23 | .byebug_history
24 |
25 | # Ignore master key for decrypting credentials and more.
26 | /config/master.key
27 |
28 | /public/packs
29 | /public/packs-test
30 | /node_modules
31 | /yarn-error.log
32 | yarn-debug.log*
33 | .yarn-integrity
34 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/.ruby-version:
--------------------------------------------------------------------------------
1 | ruby-2.5.8
2 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:2.5.8
2 | RUN apt-get update -qq && apt-get install -y nodejs npm
3 | RUN npm install -g yarn
4 | WORKDIR /snippet_sample
5 | COPY Gemfile /snippet_sample/Gemfile
6 | COPY Gemfile.lock /snippet_sample/Gemfile.lock
7 | RUN bundle install
8 | RUN rails webpacker:install
9 | COPY . /snippet_sample
10 |
11 | COPY entrypoint.sh /usr/bin/
12 | RUN chmod +x /usr/bin/entrypoint.sh
13 | ENTRYPOINT ["entrypoint.sh"]
14 | EXPOSE 3000
15 |
16 | CMD ["rails", "server", "-b", "0.0.0.0"]
17 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/README.md:
--------------------------------------------------------------------------------
1 | # README
2 |
3 | ## Square Online Store Snippets Example
4 |
5 | ### Setup
6 |
7 | The sample app currently runs on:
8 |
9 | Ruby Version: 2.5.8
10 |
11 | Rails Version: 6.1.3.1
12 |
13 | 1. To run this app locally using Docker Compose, you must have first have [Docker Compose installed](https://docs.docker.com/compose/install/)
14 | 2. Once installed you can run `docker-compose build` to build the application web container
15 | 3. Then run `docker-compose run web rails webpacker:install` to build the application's webpack manifest
16 | 4. Update the .env file at the root with following values: (WARNING: never upload .env with your credentials/secrets)
17 | ```
18 | SQUARE_APPLICATION_ID=your-app-id
19 | SQUARE_APPLICATION_SECRET=your-app-secret
20 | ```
21 | 5. Then run `docker-compose up` to start the rails web server
22 |
23 | The application will then run and be accessible at http://localhost:3000
24 |
25 | ## Feedback
26 | Rate this sample app [here](https://delighted.com/t/Z1xmKSqy)!
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/Rakefile:
--------------------------------------------------------------------------------
1 | # Add your own tasks in files placed in lib/tasks ending in .rake,
2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3 |
4 | require_relative "config/application"
5 |
6 | Rails.application.load_tasks
7 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/assets/config/manifest.js:
--------------------------------------------------------------------------------
1 | //= link_tree ../images
2 | //= link_directory ../stylesheets .css
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/assets/images/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/app/assets/images/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/channels/application_cable/channel.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Channel < ActionCable::Channel::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/channels/application_cable/connection.rb:
--------------------------------------------------------------------------------
1 | module ApplicationCable
2 | class Connection < ActionCable::Connection::Base
3 | end
4 | end
5 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/controllers/application_controller.rb:
--------------------------------------------------------------------------------
1 | class ApplicationController < ActionController::Base
2 |
3 | def require_auth
4 | redirect_to welcome_path unless session[:auth]
5 | end
6 |
7 | def square_client
8 | square_api_client = Square::SquareApiClient.new
9 | square_api_client.access_token = session[:auth]['credentials']['token']
10 |
11 | return square_api_client
12 | end
13 |
14 | end
15 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/controllers/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/app/controllers/concerns/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/controllers/sessions_controller.rb:
--------------------------------------------------------------------------------
1 | class SessionsController < ApplicationController
2 | # If you're using a strategy that POSTs during callback, you'll need to skip the authenticity token check for the callback action only.
3 | skip_before_action :verify_authenticity_token, only: :create
4 |
5 | def create
6 | session[:auth] = auth_hash
7 |
8 | redirect_to sites_url
9 | end
10 |
11 | protected
12 |
13 | def auth_hash
14 | request.env['omniauth.auth']
15 | end
16 | end
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/controllers/sites_controller.rb:
--------------------------------------------------------------------------------
1 | class SitesController < ApplicationController
2 | before_action :require_auth
3 |
4 | def index
5 | sites = square_client.list_sites
6 |
7 | redirect_to site_path sites.first.id
8 | end
9 |
10 | def show
11 | @sites = square_client.list_sites
12 | Rails.logger.debug(@sites)
13 | @site = @sites.select {|site| site.id === params[:id]}.first
14 | @snippet = square_client.get_snippet(@site['id'])
15 | @emoji = @snippet['content'][187] unless @snippet.nil?
16 | end
17 |
18 | end
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/controllers/snippets_controller.rb:
--------------------------------------------------------------------------------
1 | class SnippetsController < ApplicationController
2 | before_action :require_auth
3 | before_action :validate_emoji, only: :create
4 |
5 | def create
6 | @emoji = create_params[:emoji]
7 | square_client.upsert_snippet(params[:site_id], render_to_string(partial: 'snippets/inject'))
8 |
9 | redirect_to site_path params[:site_id]
10 | end
11 |
12 | def destroy
13 | square_client.delete_snippet params[:site_id]
14 | redirect_to site_path params[:site_id]
15 | end
16 |
17 |
18 | private
19 |
20 | def validate_emoji
21 | render json: {error: "Invalid Emoji"}, status: 400 unless ["👉","😁", "👻", "🥕", "💯", "🚀"].include?(create_params[:emoji])
22 | end
23 |
24 | def create_params
25 | params.require(:snippet).permit(:emoji)
26 | end
27 | end
28 |
29 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/controllers/welcome_controller.rb:
--------------------------------------------------------------------------------
1 | class WelcomeController < ApplicationController
2 | def index
3 | end
4 | end
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/helpers/application_helper.rb:
--------------------------------------------------------------------------------
1 | module ApplicationHelper
2 | end
3 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/javascript/channels/consumer.js:
--------------------------------------------------------------------------------
1 | // Action Cable provides the framework to deal with WebSockets in Rails.
2 | // You can generate new channels where WebSocket features live using the `bin/rails generate channel` command.
3 |
4 | import { createConsumer } from "@rails/actioncable"
5 |
6 | export default createConsumer()
7 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/javascript/channels/index.js:
--------------------------------------------------------------------------------
1 | // Load all the channels within this directory and all subdirectories.
2 | // Channel files must be named *_channel.js.
3 |
4 | const channels = require.context('.', true, /_channel\.js$/)
5 | channels.keys().forEach(channels)
6 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/javascript/packs/application.js:
--------------------------------------------------------------------------------
1 | // This file is automatically compiled by Webpack, along with any other files
2 | // present in this directory. You're encouraged to place your actual application logic in
3 | // a relevant structure within app/javascript and only use these pack files to reference
4 | // that code so it'll be compiled.
5 |
6 | import Rails from "@rails/ujs"
7 | import Turbolinks from "turbolinks"
8 | import "channels"
9 |
10 | Rails.start()
11 | Turbolinks.start()
12 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/jobs/application_job.rb:
--------------------------------------------------------------------------------
1 | class ApplicationJob < ActiveJob::Base
2 | # Automatically retry jobs that encountered a deadlock
3 | # retry_on ActiveRecord::Deadlocked
4 |
5 | # Most jobs are safe to ignore if the underlying records are no longer available
6 | # discard_on ActiveJob::DeserializationError
7 | end
8 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/mailers/application_mailer.rb:
--------------------------------------------------------------------------------
1 | class ApplicationMailer < ActionMailer::Base
2 | default from: 'from@example.com'
3 | layout 'mailer'
4 | end
5 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/models/concerns/.keep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/app/models/concerns/.keep
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/views/layouts/mailer.html.erb:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
8 |
9 |
10 |
11 | <%= yield %>
12 |
13 |
14 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/views/layouts/mailer.text.erb:
--------------------------------------------------------------------------------
1 | <%= yield %>
2 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/views/snippets/_inject.html.erb:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/connect-examples/v2/rails_snippet/app/views/welcome/index.html.erb:
--------------------------------------------------------------------------------
1 |