├── .gitignore ├── README.md ├── connect-examples ├── oauth │ ├── .gitignore │ ├── OAuthPermissions.md │ ├── java │ │ ├── .gitignore │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── squareup │ │ │ └── oauthexample │ │ │ └── OAuthHandler.java │ ├── node │ │ ├── .env.example │ │ ├── .gitignore │ │ ├── README.md │ │ ├── index.js │ │ ├── messages.js │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── public │ │ │ └── style.css │ │ └── views │ │ │ └── base.ejs │ ├── php │ │ ├── .env.example │ │ ├── .gitignore │ │ ├── README.md │ │ ├── callback.php │ │ ├── composer.json │ │ ├── messages.php │ │ ├── public │ │ │ └── style.css │ │ └── request_token.php │ ├── python-aws-chalice │ │ ├── .chalice │ │ │ ├── config.json │ │ │ └── policy-dev.json │ │ ├── .gitignore │ │ ├── README.md │ │ ├── app.py │ │ ├── chalicelib │ │ │ ├── __init__.py │ │ │ ├── oauthClient.py │ │ │ └── oauthDB.py │ │ └── requirements.txt │ ├── python │ │ ├── .env.example │ │ ├── .gitignore │ │ ├── README.md │ │ ├── oauth-flow.py │ │ ├── requirements.txt │ │ ├── static │ │ │ └── style.css │ │ └── templates │ │ │ └── base.html │ └── ruby │ │ ├── .env.example │ │ ├── .gitignore │ │ ├── Gemfile │ │ ├── Gemfile.lock │ │ ├── README.md │ │ ├── oauth-flow.rb │ │ ├── public │ │ └── style.css │ │ └── views │ │ └── base.erb ├── v1 │ ├── README.md │ ├── java │ │ ├── README.md │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── com │ │ │ └── squareup │ │ │ └── connectexamples │ │ │ ├── ItemManager.java │ │ │ ├── PaymentsReporter.java │ │ │ └── WebhookHandler.java │ ├── php │ │ ├── README.md │ │ ├── composer.json │ │ ├── item-management.php │ │ ├── payments-report.php │ │ └── webhooks.php │ ├── python │ │ ├── item-management.py │ │ ├── payments-report.py │ │ └── webhooks.py │ └── ruby │ │ ├── README.md │ │ ├── item-management.rb │ │ ├── payments-report.rb │ │ └── webhooks.rb └── v2 │ ├── README.md │ ├── csharp_payment │ ├── .gitignore │ ├── LICENSE │ ├── Pages │ │ ├── Error.cshtml │ │ ├── Error.cshtml.cs │ │ ├── ProcessPayment.cshtml │ │ ├── ProcessPayment.cshtml.cs │ │ ├── _Layout.cshtml │ │ ├── _ValidationScriptsPartial.cshtml │ │ ├── _ViewImports.cshtml │ │ ├── _ViewStart.cshtml │ │ ├── index.cshtml │ │ └── index.cshtml.cs │ ├── PaymentFormExample.png │ ├── Program.cs │ ├── README.md │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json.example │ ├── bundleconfig.json │ ├── sqRazorSample.csproj │ ├── sqRazorSample.sln │ └── wwwroot │ │ ├── css │ │ ├── sq-payment.css │ │ └── style.css │ │ ├── favicon.ico │ │ └── js │ │ ├── sq-ach.js │ │ ├── sq-apple-pay.js │ │ ├── sq-card-pay.js │ │ ├── sq-google-pay.js │ │ └── sq-payment-flow.js │ ├── graphql-sample-app │ ├── .env │ ├── .env.example │ ├── .eslintrc.json │ ├── .gitignore │ ├── README.md │ ├── bin │ │ └── script │ │ │ ├── seed-data.js │ │ │ └── test-data.json │ ├── index.js │ ├── package-lock.json │ ├── package.json │ └── queries.js │ ├── java_catalog │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── pom.xml │ └── src │ │ ├── main │ │ └── java │ │ │ └── com │ │ │ └── squareup │ │ │ └── catalog │ │ │ └── demo │ │ │ ├── Logger.java │ │ │ ├── Main.java │ │ │ ├── example │ │ │ ├── ApplyTaxToAllIItemsExample.java │ │ │ ├── CreateItemExample.java │ │ │ ├── DeduplicateTaxesExample.java │ │ │ ├── DeleteAllItemsExample.java │ │ │ ├── DeleteCategoryExample.java │ │ │ ├── Example.java │ │ │ ├── GloballyEnableAllItemsExample.java │ │ │ ├── ListCategoriesExample.java │ │ │ ├── ListDiscountsExample.java │ │ │ ├── LocationSpecificPriceExample.java │ │ │ ├── RetrieveCatalogObjectExample.java │ │ │ ├── SearchItemsExample.java │ │ │ └── clone │ │ │ │ ├── CatalogObjectCloneUtil.java │ │ │ │ ├── CategoryCloneUtil.java │ │ │ │ ├── CloneCatalogExample.java │ │ │ │ ├── CloneCatalogException.java │ │ │ │ ├── DiscountCloneUtil.java │ │ │ │ ├── ItemCloneUtil.java │ │ │ │ ├── ModifierListCloneUtil.java │ │ │ │ └── TaxCloneUtil.java │ │ │ └── util │ │ │ ├── CatalogObjectTypes.java │ │ │ ├── CatalogObjects.java │ │ │ ├── DiscountTypes.java │ │ │ ├── Errors.java │ │ │ ├── GsonProvider.java │ │ │ ├── Moneys.java │ │ │ └── Prompts.java │ │ └── test │ │ └── java │ │ └── com │ │ └── squareup │ │ └── catalog │ │ └── demo │ │ ├── example │ │ ├── DeduplicateTaxesExampleTest.java │ │ ├── RetrieveCatalogObjectExampleTest.java │ │ └── clone │ │ │ ├── CategoryCloneUtilTest.java │ │ │ ├── DiscountCloneUtilTest.java │ │ │ ├── ItemCloneUtilTest.java │ │ │ ├── ModifierListCloneUtilTest.java │ │ │ └── TaxCloneUtilTest.java │ │ └── util │ │ ├── ErrorTest.java │ │ └── MoneysTest.java │ ├── java_payment │ ├── .gitignore │ ├── LICENSE │ ├── PaymentFormExampleJava.png │ ├── Procfile │ ├── README.md │ ├── app.json │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── squareup │ │ │ │ └── connectexamples │ │ │ │ └── ecommerce │ │ │ │ ├── Main.java │ │ │ │ ├── PaymentResult.java │ │ │ │ └── TokenWrapper.java │ │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── public │ │ │ └── .well-known │ │ │ │ └── apple-developer-merchantid-domain-association │ │ │ ├── static │ │ │ ├── css │ │ │ │ ├── sq-payment.css │ │ │ │ └── style.css │ │ │ └── js │ │ │ │ ├── sq-ach.js │ │ │ │ ├── sq-apple-pay.js │ │ │ │ ├── sq-card-pay.js │ │ │ │ ├── sq-google-pay.js │ │ │ │ └── sq-payment-flow.js │ │ │ └── templates │ │ │ └── index.html │ └── system.properties │ ├── node_bookings │ ├── .env.example │ ├── .eslintrc.json │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── app.js │ ├── bin │ │ ├── images │ │ │ ├── cancel-booking-screenshot.png │ │ │ ├── confirmation-page-screenshot.png │ │ │ ├── contact-details-screenshot.png │ │ │ ├── modify-booking-screenshot.png │ │ │ ├── select-availability-screenshot.png │ │ │ ├── select-services-screenshot.png │ │ │ └── select-staff-screenshot.png │ │ ├── script │ │ │ ├── seed-data.js │ │ │ └── service-items.json │ │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── images │ │ │ ├── back-arrow.svg │ │ │ ├── blank-logo-sm.svg │ │ │ ├── blank-logo.svg │ │ │ ├── plus.svg │ │ │ ├── side-caret-selected.svg │ │ │ ├── side-caret.svg │ │ │ └── success.svg │ │ ├── js │ │ │ └── date-picker-handler.js │ │ └── stylesheets │ │ │ ├── datepicker.css │ │ │ └── style.css │ ├── routes │ │ ├── availability.js │ │ ├── booking.js │ │ ├── contact.js │ │ ├── index.js │ │ ├── services.js │ │ └── staff.js │ ├── util │ │ ├── date-helpers.js │ │ └── square-client.js │ └── views │ │ ├── functions.ejs │ │ ├── pages │ │ ├── availability.ejs │ │ ├── confirmation.ejs │ │ ├── contact.ejs │ │ ├── formatted-error.ejs │ │ ├── reschedule.ejs │ │ ├── select-service.ejs │ │ └── select-staff.ejs │ │ └── partials │ │ ├── date-selector.ejs │ │ └── header.ejs │ ├── node_catalog_subscription │ ├── .gitignore │ ├── README.md │ ├── app │ │ ├── .env.example │ │ ├── eslint.config.mjs │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── postcss.config.js │ │ ├── public │ │ │ ├── favicon.ico │ │ │ ├── index.html │ │ │ ├── logo192.png │ │ │ ├── logo512.png │ │ │ ├── manifest.json │ │ │ └── robots.txt │ │ ├── src │ │ │ ├── App.tsx │ │ │ ├── components │ │ │ │ ├── ComponentLayout │ │ │ │ │ └── index.tsx │ │ │ │ ├── CreditCardGroup │ │ │ │ │ ├── CardsOnFile │ │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── NewCreditCardInput │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── index.tsx │ │ │ │ ├── Customers │ │ │ │ │ ├── CustomerTile │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── index.tsx │ │ │ │ ├── HelperComponents │ │ │ │ │ └── Status │ │ │ │ │ │ └── index.tsx │ │ │ │ ├── ItemCatalog │ │ │ │ │ ├── ItemTile │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── index.tsx │ │ │ │ ├── Layout │ │ │ │ │ └── index.tsx │ │ │ │ ├── Navbar │ │ │ │ │ └── index.tsx │ │ │ │ ├── NavigationButtons │ │ │ │ │ └── index.tsx │ │ │ │ ├── ReviewOrderDetails │ │ │ │ │ └── index.tsx │ │ │ │ ├── Skeleton │ │ │ │ │ └── index.tsx │ │ │ │ └── SubscriptionPlans │ │ │ │ │ ├── SubscriptionTile │ │ │ │ │ └── index.tsx │ │ │ │ │ └── index.tsx │ │ │ ├── context │ │ │ │ └── AppContext.ts │ │ │ ├── index.css │ │ │ ├── index.tsx │ │ │ ├── logo.svg │ │ │ ├── pages │ │ │ │ ├── CustomerOverview │ │ │ │ │ ├── SubscriptionsTable │ │ │ │ │ │ └── index.tsx │ │ │ │ │ └── index.tsx │ │ │ │ ├── Home │ │ │ │ │ └── index.tsx │ │ │ │ └── SubscriptionDetails │ │ │ │ │ ├── InvoicesTable │ │ │ │ │ └── index.tsx │ │ │ │ │ ├── SubscriptionSections │ │ │ │ │ └── index.tsx │ │ │ │ │ └── index.tsx │ │ │ ├── react-app-env.d.ts │ │ │ ├── reportWebVitals.ts │ │ │ ├── setupTests.ts │ │ │ └── utils │ │ │ │ ├── apiQueries.ts │ │ │ │ └── helpers.ts │ │ ├── tailwind.config.js │ │ └── tsconfig.json │ └── server │ │ ├── .env.example │ │ ├── bin │ │ └── script │ │ │ ├── img │ │ │ ├── autumn-soup@2x.png │ │ │ ├── avocado-toast@2x.png │ │ │ ├── bacon-burger@2x.png │ │ │ ├── bbq-chicken-pizza@2x.png │ │ │ ├── caprese-salad@2x.png │ │ │ ├── chicken-caesar-wrap@2x.png │ │ │ ├── chicken-sandwich@2x.png │ │ │ ├── egg-sunnyside-up-on-toast@2x.png │ │ │ ├── grilled-steak@2x.png │ │ │ ├── italian-sandwich@2x.png │ │ │ ├── meatballs@2x.png │ │ │ ├── mediterranean-yogurt-bowl@2x.png │ │ │ ├── oatmeal-with-fruit@2x.png │ │ │ ├── pancakes-with-fruit@2x.png │ │ │ ├── pesto-pasta@2x.png │ │ │ ├── salmon-with-zucchini@2x.png │ │ │ ├── steak-tacos@2x.png │ │ │ ├── strawberry-smoothie@2x.png │ │ │ ├── vegetarian-pizza@2x.png │ │ │ ├── vegetarian-wrap@2x.png │ │ │ └── veggie-delight-salad@2x.png │ │ │ ├── sample-seed-data.json │ │ │ └── seed-catalog.js │ │ ├── eslint.config.mjs │ │ ├── index.ts │ │ ├── package-lock.json │ │ ├── package.json │ │ ├── routes │ │ ├── cards.ts │ │ ├── catalog.ts │ │ ├── customers.ts │ │ ├── invoices.ts │ │ └── subscriptions.ts │ │ ├── square-client │ │ └── index.ts │ │ └── tsconfig.json │ ├── node_gift-cards │ ├── .env.example │ ├── .eslintrc.json │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── app.js │ ├── bin │ │ ├── images │ │ │ ├── gift-cards-api-app-10.png │ │ │ ├── gift-cards-api-app-20.png │ │ │ ├── gift-cards-api-app-30.png │ │ │ └── gift-cards-api-app-40.png │ │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── images │ │ │ ├── amex.svg │ │ │ ├── caret.svg │ │ │ ├── ellipsis.svg │ │ │ ├── giftCardImage.png │ │ │ ├── left-arrow.svg │ │ │ ├── loading.svg │ │ │ ├── mastercard.svg │ │ │ ├── no-card.svg │ │ │ ├── profile.svg │ │ │ ├── selected.svg │ │ │ ├── success.svg │ │ │ └── visa.svg │ │ ├── js │ │ │ ├── amount-bar.js │ │ │ ├── bwip-js-min.js │ │ │ ├── generate-barcode.js │ │ │ ├── loading.js │ │ │ ├── pretty-dropdown-menu.js │ │ │ └── pretty-select-dropdown.js │ │ └── stylesheets │ │ │ ├── pretty-dropdown-menu.css │ │ │ ├── pretty-select-dropdown.css │ │ │ └── style.css │ ├── routes │ │ ├── dashboard.js │ │ ├── gift-card.js │ │ ├── index.js │ │ └── seed.js │ ├── util │ │ ├── middleware.js │ │ └── square-client.js │ └── views │ │ ├── functions.ejs │ │ ├── pages │ │ ├── add-funds.ejs │ │ ├── card-detail.ejs │ │ ├── dashboard.ejs │ │ ├── error.ejs │ │ ├── history.ejs │ │ └── login.ejs │ │ └── partials │ │ └── header.ejs │ ├── node_invoices │ ├── .env.example │ ├── .eslintrc.js │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── app.js │ ├── bin │ │ ├── images │ │ │ ├── screenshot-1.png │ │ │ ├── screenshot-2.png │ │ │ └── screenshot-3.png │ │ ├── script │ │ │ ├── README.md │ │ │ └── seed-data.js │ │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── README.md │ │ └── stylesheets │ │ │ ├── index.css │ │ │ ├── invoice.css │ │ │ └── main.css │ ├── routes │ │ ├── README.md │ │ ├── index.js │ │ ├── invoice.js │ │ └── management.js │ ├── util │ │ ├── README.md │ │ └── square-client.js │ └── views │ │ ├── README.md │ │ ├── error.pug │ │ ├── index.pug │ │ ├── invoice.pug │ │ ├── layout.pug │ │ └── management.pug │ ├── node_orders-payments │ ├── .env.example │ ├── .eslintrc.js │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── app.js │ ├── bin │ │ ├── images │ │ │ ├── Order-Ahead-Diagram-10.png │ │ │ ├── Order-Ahead-Diagram-100.png │ │ │ ├── Order-Ahead-Diagram-110.png │ │ │ ├── Order-Ahead-Diagram-20.png │ │ │ ├── Order-Ahead-Diagram-30.png │ │ │ ├── Order-Ahead-Diagram-40.png │ │ │ ├── Order-Ahead-Diagram-50.png │ │ │ ├── Order-Ahead-Diagram-60.png │ │ │ ├── Order-Ahead-Diagram-70.png │ │ │ ├── Order-Ahead-Diagram-80.png │ │ │ └── Order-Ahead-Diagram-90.png │ │ ├── script │ │ │ ├── README.md │ │ │ ├── img │ │ │ │ ├── autumn-soup@2x.png │ │ │ │ ├── bacon-burger@2x.png │ │ │ │ ├── chicken-sandwich@2x.png │ │ │ │ ├── egg-sunnyside-up-on-toast@2x.png │ │ │ │ ├── grilled-steak@2x.png │ │ │ │ ├── italian-sandwich@2x.png │ │ │ │ ├── meatballs@2x.png │ │ │ │ ├── mediterranean-yogurt-bowl@2x.png │ │ │ │ ├── oatmeal-with-fruit@2x.png │ │ │ │ ├── pancakes-with-fruit@2x.png │ │ │ │ ├── salmon-with-zucchini@2x.png │ │ │ │ └── steak-tacos@2x.png │ │ │ ├── sample-seed-data.json │ │ │ └── seed-catalog.js │ │ └── www │ ├── models │ │ ├── README.md │ │ ├── catalog-item.js │ │ ├── catalog-list.js │ │ ├── delivery-pickup-times.js │ │ ├── location-info.js │ │ └── order-info.js │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── README.md │ │ ├── js │ │ │ ├── products-page.js │ │ │ ├── sq-card-pay.js │ │ │ └── sq-payment-flow.js │ │ └── stylesheets │ │ │ ├── checkout.css │ │ │ ├── header.css │ │ │ ├── main.css │ │ │ ├── products.css │ │ │ └── sq-payment.css │ ├── routes │ │ ├── README.md │ │ ├── checkout.js │ │ ├── index.js │ │ └── order-confirmation.js │ ├── util │ │ ├── README.md │ │ └── square-client.js │ └── views │ │ ├── README.md │ │ ├── checkout │ │ ├── add-delivery-details.pug │ │ ├── add-pickup-details.pug │ │ ├── choose-delivery-pickup.pug │ │ └── payment.pug │ │ ├── error.pug │ │ ├── includes │ │ ├── add-loyalty-point.pug │ │ ├── attach-loyalty-account.pug │ │ ├── delivery-confirmation.pug │ │ ├── delivery-details.pug │ │ ├── delivery-info-input.pug │ │ ├── header.pug │ │ ├── loyalty-panel.pug │ │ ├── order-summary.pug │ │ ├── pickup-confirmation.pug │ │ ├── pickup-details.pug │ │ ├── pickup-info-input.pug │ │ └── redeem-loyalty-reward.pug │ │ ├── index.pug │ │ ├── layout.pug │ │ └── order-confirmation.pug │ ├── node_payment │ ├── .env.example │ ├── .gitignore │ ├── .well-known │ │ └── apple-developer-merchantid-domain-association │ ├── LICENSE │ ├── PaymentFormExampleNode.png │ ├── README.md │ ├── app.js │ ├── bin │ │ └── www │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── js │ │ │ ├── sq-ach.js │ │ │ ├── sq-apple-pay.js │ │ │ ├── sq-card-pay.js │ │ │ ├── sq-google-pay.js │ │ │ └── sq-payment-flow.js │ │ └── stylesheets │ │ │ ├── sq-payment.css │ │ │ └── style.css │ ├── routes │ │ └── index.js │ ├── util │ │ └── square-client.js │ └── views │ │ ├── error.pug │ │ ├── index.pug │ │ └── layout.pug │ ├── node_subscription │ ├── .env.example │ ├── .eslintrc.js │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── app.js │ ├── bin │ │ ├── images │ │ │ ├── screenshot-1.png │ │ │ ├── screenshot-2.png │ │ │ ├── screenshot-3.png │ │ │ ├── screenshot-4.png │ │ │ └── screenshot-5.png │ │ ├── script │ │ │ ├── README.md │ │ │ ├── sample-seed-data.json │ │ │ └── seed-data.js │ │ └── www │ ├── models │ │ ├── README.md │ │ └── subscription-details-info.js │ ├── package-lock.json │ ├── package.json │ ├── public │ │ ├── README.md │ │ └── stylesheets │ │ │ ├── index.css │ │ │ ├── main.css │ │ │ └── subscription.css │ ├── routes │ │ ├── README.md │ │ ├── index.js │ │ ├── management.js │ │ └── subscription.js │ ├── util │ │ ├── README.md │ │ └── square-client.js │ └── views │ │ ├── README.md │ │ ├── error.pug │ │ ├── index.pug │ │ ├── layout.pug │ │ ├── management.pug │ │ └── subscription.pug │ ├── php_payment │ ├── .env.example │ ├── .gitignore │ ├── .well-known │ │ └── apple-developer-merchantid-domain-association │ ├── README.md │ ├── composer.json │ ├── index.php │ ├── process-payment.php │ ├── public │ │ ├── js │ │ │ ├── sq-ach.js │ │ │ ├── sq-apple-pay.js │ │ │ ├── sq-card-pay.js │ │ │ ├── sq-google-pay.js │ │ │ └── sq-payment-flow.js │ │ └── stylesheets │ │ │ ├── sq-payment.css │ │ │ └── style.css │ └── utils │ │ └── location-info.php │ ├── python_payment │ ├── .gitignore │ ├── .well-known │ │ └── apple-developer-merchantid-domain-association │ ├── PaymentFormExamplePython.png │ ├── README.md │ ├── config.ini.example │ ├── main.py │ ├── requirements.txt │ └── static │ │ ├── js │ │ ├── sq-ach.js │ │ ├── sq-apple-pay.js │ │ ├── sq-card-pay.js │ │ ├── sq-google-pay.js │ │ └── sq-payment-flow.js │ │ └── stylesheets │ │ ├── sq-payment.css │ │ └── style.css │ ├── rails_payment │ ├── .env.example │ ├── .gitignore │ ├── .ruby-version │ ├── Gemfile │ ├── Gemfile.lock │ ├── Procfile │ ├── README.md │ ├── Rakefile │ ├── app │ │ ├── assets │ │ │ ├── apple-developer-merchantid-domain-association │ │ │ ├── config │ │ │ │ └── manifest.js │ │ │ ├── images │ │ │ │ └── .keep │ │ │ ├── javascripts │ │ │ │ ├── application.js │ │ │ │ ├── sq-ach.js │ │ │ │ ├── sq-apple-pay.js │ │ │ │ ├── sq-card-pay.js │ │ │ │ ├── sq-google-pay.js │ │ │ │ └── sq-payment-flow.js │ │ │ └── stylesheets │ │ │ │ ├── application.css │ │ │ │ ├── sq-payment.css │ │ │ │ └── style.css │ │ ├── controllers │ │ │ ├── apple_controller.rb │ │ │ ├── application_controller.rb │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ ├── payments_controller.rb │ │ │ └── welcome_controller.rb │ │ ├── helpers │ │ │ └── square_api_helper.rb │ │ ├── mailers │ │ │ └── .keep │ │ ├── models │ │ │ ├── .keep │ │ │ └── concerns │ │ │ │ └── .keep │ │ └── views │ │ │ ├── layouts │ │ │ └── index.html.erb │ │ │ └── welcome │ │ │ └── index.html.erb │ ├── bin │ │ ├── bundle │ │ ├── rails │ │ ├── rake │ │ ├── setup │ │ └── spring │ ├── config.ru │ ├── config │ │ ├── application.rb │ │ ├── boot.rb │ │ ├── database.yml │ │ ├── environment.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── production.rb │ │ │ └── test.rb │ │ ├── initializers │ │ │ ├── assets.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── cookies_serializer.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── inflections.rb │ │ │ ├── mime_types.rb │ │ │ ├── session_store.rb │ │ │ └── wrap_parameters.rb │ │ ├── locales │ │ │ └── en.yml │ │ ├── routes.rb │ │ └── secrets.yml │ ├── db │ │ ├── schema.rb │ │ └── seeds.rb │ ├── lib │ │ ├── assets │ │ │ └── .keep │ │ └── tasks │ │ │ └── .keep │ ├── log │ │ └── .keep │ ├── public │ │ ├── 404.html │ │ ├── 422.html │ │ ├── 500.html │ │ ├── favicon.ico │ │ └── robots.txt │ └── test │ │ ├── controllers │ │ ├── .keep │ │ ├── payments_controller_test.rb │ │ └── welcome_controller_test.rb │ │ ├── fixtures │ │ └── .keep │ │ ├── helpers │ │ └── .keep │ │ ├── integration │ │ └── .keep │ │ ├── models │ │ └── .keep │ │ └── test_helper.rb │ ├── rails_snippet │ ├── .browserslistrc │ ├── .env │ ├── .gitattributes │ ├── .gitignore │ ├── .ruby-version │ ├── Dockerfile │ ├── Gemfile │ ├── Gemfile.lock │ ├── README.md │ ├── Rakefile │ ├── app │ │ ├── assets │ │ │ ├── config │ │ │ │ └── manifest.js │ │ │ ├── images │ │ │ │ └── .keep │ │ │ └── stylesheets │ │ │ │ └── application.css │ │ ├── channels │ │ │ └── application_cable │ │ │ │ ├── channel.rb │ │ │ │ └── connection.rb │ │ ├── controllers │ │ │ ├── application_controller.rb │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ ├── sessions_controller.rb │ │ │ ├── sites_controller.rb │ │ │ ├── snippets_controller.rb │ │ │ └── welcome_controller.rb │ │ ├── helpers │ │ │ └── application_helper.rb │ │ ├── javascript │ │ │ ├── channels │ │ │ │ ├── consumer.js │ │ │ │ └── index.js │ │ │ └── packs │ │ │ │ └── application.js │ │ ├── jobs │ │ │ └── application_job.rb │ │ ├── mailers │ │ │ └── application_mailer.rb │ │ ├── models │ │ │ └── concerns │ │ │ │ └── .keep │ │ └── views │ │ │ ├── layouts │ │ │ ├── application.html.erb │ │ │ ├── mailer.html.erb │ │ │ └── mailer.text.erb │ │ │ ├── sites │ │ │ └── show.html.erb │ │ │ ├── snippets │ │ │ └── _inject.html.erb │ │ │ └── welcome │ │ │ └── index.html.erb │ ├── babel.config.js │ ├── bin │ │ ├── bundle │ │ ├── rails │ │ ├── rake │ │ ├── setup │ │ ├── spring │ │ ├── webpack │ │ ├── webpack-dev-server │ │ └── yarn │ ├── config.ru │ ├── config │ │ ├── application.rb │ │ ├── boot.rb │ │ ├── cable.yml │ │ ├── credentials.yml.enc │ │ ├── environment.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── production.rb │ │ │ └── test.rb │ │ ├── initializers │ │ │ ├── application_controller_renderer.rb │ │ │ ├── assets.rb │ │ │ ├── backtrace_silencers.rb │ │ │ ├── content_security_policy.rb │ │ │ ├── cookies_serializer.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── inflections.rb │ │ │ ├── mime_types.rb │ │ │ ├── omniauth.rb │ │ │ ├── permissions_policy.rb │ │ │ └── wrap_parameters.rb │ │ ├── locales │ │ │ └── en.yml │ │ ├── puma.rb │ │ ├── routes.rb │ │ ├── spring.rb │ │ ├── webpack │ │ │ ├── development.js │ │ │ ├── environment.js │ │ │ ├── production.js │ │ │ └── test.js │ │ └── webpacker.yml │ ├── docker-compose.yml │ ├── entrypoint.sh │ ├── lib │ │ ├── assets │ │ │ └── .keep │ │ ├── square │ │ │ └── square_api_client.rb │ │ └── tasks │ │ │ └── .keep │ ├── log │ │ └── .keep │ ├── package.json │ ├── postcss.config.js │ ├── public │ │ ├── 404.html │ │ ├── 422.html │ │ ├── 500.html │ │ ├── apple-touch-icon-precomposed.png │ │ ├── apple-touch-icon.png │ │ ├── favicon.ico │ │ └── robots.txt │ ├── test │ │ ├── application_system_test_case.rb │ │ ├── channels │ │ │ └── application_cable │ │ │ │ └── connection_test.rb │ │ ├── controllers │ │ │ └── .keep │ │ ├── fixtures │ │ │ └── files │ │ │ │ └── .keep │ │ ├── helpers │ │ │ └── .keep │ │ ├── integration │ │ │ └── .keep │ │ ├── mailers │ │ │ └── .keep │ │ ├── models │ │ │ └── .keep │ │ ├── system │ │ │ └── .keep │ │ └── test_helper.rb │ ├── tmp │ │ ├── .keep │ │ └── pids │ │ │ └── .keep │ └── yarn.lock │ └── v2_deprecated │ ├── csharp_checkout │ ├── .bowerrc │ ├── .gitignore │ ├── LICENSE │ ├── Pages │ │ ├── Checkout.cshtml │ │ ├── Checkout.cshtml.cs │ │ ├── Error.cshtml │ │ ├── Error.cshtml.cs │ │ ├── Index.cshtml │ │ ├── Index.cshtml.cs │ │ ├── _Layout.cshtml │ │ ├── _ValidationScriptsPartial.cshtml │ │ ├── _ViewImports.cshtml │ │ └── _ViewStart.cshtml │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── README.md │ ├── Startup.cs │ ├── appsettings.Production.json.example │ ├── appsettings.Sandbox.json.example │ ├── bower.json │ ├── bundleconfig.json │ ├── checkout.png │ ├── confirmation.png │ ├── csharp_checkout.csproj │ ├── csharp_checkout.sln │ └── wwwroot │ │ ├── css │ │ ├── main.css │ │ └── normalize.css │ │ └── favicon.ico │ └── php_checkout │ ├── .env.example │ ├── .gitignore │ ├── README.md │ ├── checkout.php │ ├── composer.json │ ├── confirmation.php │ ├── index.php │ ├── main.css │ └── normalize.css └── templates ├── README.md ├── php └── sq_config.php └── web-ui └── web-payments-sdk ├── js ├── sq-ach.js ├── sq-apple-pay.js ├── sq-card-pay.js ├── sq-google-pay.js └── sq-payment-flow.js └── stylesheets ├── sq-payment.css └── style.css /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | vendor/ 3 | composer.phar 4 | composer.lock 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Square Connect API Examples 2 | 3 | This repository contains code samples demonstrating the functionality of the 4 | Square Connect API and templates to simplify use of our SDKs and APIs. 5 | 6 | 7 | ## In this repository 8 | 9 | * `connect-examples/oauth` - samples demonstrating OAuth functionality 10 | * `connect-examples/v1` - DEPRECATED: samples demonstrating Connect v1 functionality 11 | * `connect-examples/v2` - samples demonstrating Connect v2 functionality 12 | * `templates/` - code blocks and function definitions to simplify common usage 13 | 14 | 15 | ## Getting help 16 | 17 | Complete documentation for Square APIs is available at 18 | [developer.squareup.com/docs]. 19 | 20 | If you have questions about Square Connect API features or implementation, 21 | you can ask for help on our [Developer Forums] or in our [Discord community]. 22 | 23 | [//]: # "Link anchor definitions" 24 | [Developer Forums]: https://developer.squareup.com/forums 25 | [Discord community]: https://discord.com/invite/squaredev 26 | [developer.squareup.com/docs]: https://developer.squareup.com/docs 27 | -------------------------------------------------------------------------------- /connect-examples/oauth/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | .project 3 | .env 4 | -------------------------------------------------------------------------------- /connect-examples/oauth/OAuthPermissions.md: -------------------------------------------------------------------------------- 1 | # Square Connect v2 API OAuth Scopes 2 | 3 | The Square Connect v2 API requires OAuth scopes with every call to a Connect 4 | endpoint. [OAuth: Permissions Reference](https://developer.squareup.com/docs/oauth-api/square-permissions) 5 | provided all needed permissions (scopes) for each endpoint in a Connect v2 service. 6 | -------------------------------------------------------------------------------- /connect-examples/oauth/java/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .settings/* 3 | dependency-reduced-pom.xml 4 | -------------------------------------------------------------------------------- /connect-examples/oauth/node/.env.example: -------------------------------------------------------------------------------- 1 | SQ_ENVIRONMENT=your-environment 2 | SQ_APPLICATION_ID=your-application-id 3 | SQ_APPLICATION_SECRET=your-application-secret -------------------------------------------------------------------------------- /connect-examples/oauth/node/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules 3 | -------------------------------------------------------------------------------- /connect-examples/oauth/node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "node-oauth-walkthrough", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node index.js" 8 | }, 9 | "keywords": [], 10 | "dependencies": { 11 | "cookie-parser": "*", 12 | "dotenv": "^8.2.0", 13 | "express": "*", 14 | "square": "^33.0.0", 15 | "ejs": "*" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /connect-examples/oauth/node/public/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://square-fonts-production-f.squarecdn.com/square-sans.min.css); 2 | 3 | html { 4 | color: #151c1f; 5 | font-family: var(--square-sans-text); 6 | font-size: 16px; 7 | line-height: 24px; 8 | -webkit-font-smoothing: antialiased 9 | } 10 | 11 | h1 { 12 | color: rgba(0, 95, 229, 1); 13 | } 14 | 15 | a { 16 | color: rgba(0, 106, 255, 1); 17 | text-decoration: none; 18 | } 19 | 20 | a:hover { 21 | color: rgba(0, 95, 229, 1); 22 | } 23 | 24 | .wrapper { 25 | width: 100%; 26 | height: 100%; 27 | display: flex; 28 | align-items: center; 29 | justify-content: center; 30 | } 31 | 32 | .messages { 33 | max-width: 700px; 34 | padding: 40px; 35 | background-color: rgba(0, 0, 0, 0.02); 36 | } 37 | 38 | .btn { 39 | background-color: rgba(0, 106, 255, 1); 40 | color: white; 41 | border-radius: 6px; 42 | padding: 20px 16px 20px 16px; 43 | transition: background-color .2s ease, color .2s ease; 44 | } 45 | 46 | .btn:hover { 47 | background-color: rgba(0, 85, 204, 1); 48 | color: white; 49 | } 50 | -------------------------------------------------------------------------------- /connect-examples/oauth/node/views/base.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | <%- content %> 8 | -------------------------------------------------------------------------------- /connect-examples/oauth/php/.env.example: -------------------------------------------------------------------------------- 1 | SQ_ENVIRONMENT=your-environment 2 | SQ_APPLICATION_ID=your-application-id 3 | SQ_APPLICATION_SECRET=your-application-secret -------------------------------------------------------------------------------- /connect-examples/oauth/php/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /connect-examples/oauth/php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "square/square": "33.0.0.20231115", 4 | "vlucas/phpdotenv": "^5.6.0" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /connect-examples/oauth/php/public/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://square-fonts-production-f.squarecdn.com/square-sans.min.css); 2 | 3 | html { 4 | color: #151c1f; 5 | font-family: var(--square-sans-text); 6 | font-size: 16px; 7 | line-height: 24px; 8 | -webkit-font-smoothing: antialiased 9 | } 10 | 11 | h1 { 12 | color: rgba(0, 95, 229, 1); 13 | } 14 | 15 | a { 16 | color: rgba(0, 106, 255, 1); 17 | text-decoration: none; 18 | } 19 | 20 | a:hover { 21 | color: rgba(0, 95, 229, 1); 22 | } 23 | 24 | .wrapper { 25 | width: 100%; 26 | height: 100%; 27 | display: flex; 28 | align-items: center; 29 | justify-content: center; 30 | } 31 | 32 | .messages { 33 | max-width: 700px; 34 | padding: 40px; 35 | background-color: rgba(0, 0, 0, 0.02); 36 | } 37 | 38 | .btn { 39 | background-color: rgba(0, 106, 255, 1); 40 | color: white; 41 | border-radius: 6px; 42 | padding: 20px 16px 20px 16px; 43 | transition: background-color .2s ease, color .2s ease; 44 | } 45 | 46 | .btn:hover { 47 | background-color: rgba(0, 85, 204, 1); 48 | color: white; 49 | } 50 | -------------------------------------------------------------------------------- /connect-examples/oauth/python-aws-chalice/.chalice/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "app_name": "oauth-example", 4 | "autogen_policy": false, 5 | "stages": { 6 | "dev": { 7 | "api_gateway_stage": "api", 8 | "environment_variables": { 9 | "environment": "sandbox", 10 | "base_url": "https://connect.squareupsandbox.com", 11 | "permissions": "ITEMS_READ PAYMENTS_READ", 12 | "session": "true", 13 | "oauth_table_name": "oauth_users" 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /connect-examples/oauth/python-aws-chalice/.chalice/policy-dev.json: -------------------------------------------------------------------------------- 1 | { 2 | "Version": "2012-10-17", 3 | "Statement": [ 4 | { 5 | "Effect": "Allow", 6 | "Action": [ 7 | "dynamodb:CreateTable", 8 | "dynamodb:DeleteItem", 9 | "dynamodb:PutItem", 10 | "dynamodb:Scan", 11 | "dynamodb:UpdateItem", 12 | "dynamodb:GetItem" 13 | ], 14 | "Resource": [ 15 | "*" 16 | ] 17 | }, 18 | { 19 | "Effect": "Allow", 20 | "Action": [ 21 | "logs:CreateLogGroup", 22 | "logs:CreateLogStream", 23 | "logs:PutLogEvents" 24 | ], 25 | "Resource": "arn:aws:logs:*:*:*" 26 | } 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /connect-examples/oauth/python-aws-chalice/.gitignore: -------------------------------------------------------------------------------- 1 | .chalice/deployments/ 2 | .chalice/venv/ 3 | __pycache__ -------------------------------------------------------------------------------- /connect-examples/oauth/python-aws-chalice/chalicelib/__init__.py: -------------------------------------------------------------------------------- 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 | # Unless required by applicable law or agreed to in writing, software 9 | # distributed under the License is distributed on an "AS IS" BASIS, 10 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | # See the License for the specific language governing permissions and 12 | # limitations under the License. -------------------------------------------------------------------------------- /connect-examples/oauth/python-aws-chalice/requirements.txt: -------------------------------------------------------------------------------- 1 | chalice==1.12.0 2 | boto3==1.11.11 3 | squareup==22.0.0.20220921 4 | cryptography===3.3.2 -------------------------------------------------------------------------------- /connect-examples/oauth/python/.env.example: -------------------------------------------------------------------------------- 1 | SQ_ENVIRONMENT=your-environment 2 | SQ_APPLICATION_ID=your-application-id 3 | SQ_APPLICATION_SECRET=your-application-secret -------------------------------------------------------------------------------- /connect-examples/oauth/python/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | __pycache__/ 3 | venv/ -------------------------------------------------------------------------------- /connect-examples/oauth/python/requirements.txt: -------------------------------------------------------------------------------- 1 | flask 2 | squareup==33.0.0.20231115 3 | python-dotenv 4 | -------------------------------------------------------------------------------- /connect-examples/oauth/python/static/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://square-fonts-production-f.squarecdn.com/square-sans.min.css); 2 | 3 | html { 4 | color: #151c1f; 5 | font-family: var(--square-sans-text); 6 | font-size: 16px; 7 | line-height: 24px; 8 | -webkit-font-smoothing: antialiased 9 | } 10 | 11 | h1 { 12 | color: rgba(0, 95, 229, 1); 13 | } 14 | 15 | a { 16 | color: rgba(0, 106, 255, 1); 17 | text-decoration: none; 18 | } 19 | 20 | a:hover { 21 | color: rgba(0, 95, 229, 1); 22 | } 23 | 24 | .wrapper { 25 | width: 100%; 26 | height: 100%; 27 | display: flex; 28 | align-items: center; 29 | justify-content: center; 30 | } 31 | 32 | .messages { 33 | max-width: 700px; 34 | padding: 40px; 35 | background-color: rgba(0, 0, 0, 0.02); 36 | } 37 | 38 | .btn { 39 | background-color: rgba(0, 106, 255, 1); 40 | color: white; 41 | border-radius: 6px; 42 | padding: 20px 16px 20px 16px; 43 | transition: background-color .2s ease, color .2s ease; 44 | } 45 | 46 | .btn:hover { 47 | background-color: rgba(0, 85, 204, 1); 48 | color: white; 49 | } 50 | -------------------------------------------------------------------------------- /connect-examples/oauth/python/templates/base.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{content|safe}} -------------------------------------------------------------------------------- /connect-examples/oauth/ruby/.env.example: -------------------------------------------------------------------------------- 1 | SQ_ENVIRONMENT=your-environment 2 | SQ_APPLICATION_ID=your-application-id 3 | SQ_APPLICATION_SECRET=your-application-secret -------------------------------------------------------------------------------- /connect-examples/oauth/ruby/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | -------------------------------------------------------------------------------- /connect-examples/oauth/ruby/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | ruby '3.2.2' 4 | gem 'square.rb', '~> 34.0.0.20231115 ' 5 | gem 'sinatra', '~> 3.1.0' 6 | gem 'thin', '~> 1.8.0' 7 | gem 'dotenv-rails', groups: [:development, :test] -------------------------------------------------------------------------------- /connect-examples/oauth/ruby/public/style.css: -------------------------------------------------------------------------------- 1 | @import url(https://square-fonts-production-f.squarecdn.com/square-sans.min.css); 2 | 3 | html { 4 | color: #151c1f; 5 | font-family: var(--square-sans-text); 6 | font-size: 16px; 7 | line-height: 24px; 8 | -webkit-font-smoothing: antialiased 9 | } 10 | 11 | h1 { 12 | color: rgba(0, 95, 229, 1); 13 | } 14 | 15 | a { 16 | color: rgba(0, 106, 255, 1); 17 | text-decoration: none; 18 | } 19 | 20 | a:hover { 21 | color: rgba(0, 95, 229, 1); 22 | } 23 | 24 | .wrapper { 25 | width: 100%; 26 | height: 100%; 27 | display: flex; 28 | align-items: center; 29 | justify-content: center; 30 | } 31 | 32 | .messages { 33 | max-width: 700px; 34 | padding: 40px; 35 | background-color: rgba(0, 0, 0, 0.02); 36 | } 37 | 38 | .btn { 39 | background-color: rgba(0, 106, 255, 1); 40 | color: white; 41 | border-radius: 6px; 42 | padding: 20px 16px 20px 16px; 43 | transition: background-color .2s ease, color .2s ease; 44 | } 45 | 46 | .btn:hover { 47 | background-color: rgba(0, 85, 204, 1); 48 | color: white; 49 | } 50 | -------------------------------------------------------------------------------- /connect-examples/oauth/ruby/views/base.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= content %> -------------------------------------------------------------------------------- /connect-examples/v1/README.md: -------------------------------------------------------------------------------- 1 | ## The _v1_ code samples are deprecated 2 | The samples in this folder are no longer maintained. For the most up-to-date samples, please refer to the following: 3 | 4 | * [`connect-examples/v2`](https://github.com/square/connect-api-examples/tree/master/connect-examples/v2) - samples demonstrating Square API functionality 5 | * [`connect-examples/oauth`](https://github.com/square/connect-api-examples/tree/master/connect-examples/oauth) - samples demonstrating OAuth functionality 6 | * [`templates`](https://github.com/square/connect-api-examples/tree/master/templates) - code blocks and function definitions to simplify common usage 7 | -------------------------------------------------------------------------------- /connect-examples/v1/php/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "mashape/unirest-php": "3.*" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /connect-examples/v1/ruby/README.md: -------------------------------------------------------------------------------- 1 | ## Ruby V1 example 2 | 3 | The samples in this directory demonstrate basic use of Square Connect API v1 in Ruby. Before you run any of these samples, be sure to complete the steps described below. 4 | 5 | ### How to run 6 | * First, install `unirest` by opening your terminal 7 | and typing: 8 | ``` 9 | gem install unirest 10 | gem install sinatra 11 | ``` 12 | * Fill in the required variables (`REPLACE_ME`) 13 | in all of the files 14 | * Then run each file individually: 15 | ``` 16 | ruby item-management.rb 17 | ruby payments-report.rb 18 | ``` 19 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/.gitignore: -------------------------------------------------------------------------------- 1 | .vs 2 | bin 3 | obj 4 | packages 5 | *.userprefs 6 | appsettings.json 7 | appsettings.*.json 8 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model ErrorModel 3 | @{ 4 | ViewData["Title"] = "Error"; 5 | } 6 | 7 |

Error.

8 |

An error occurred while processing your request.

9 | 10 | @if (Model.ShowRequestId) 11 | { 12 |

13 | Request ID: @Model.RequestId 14 |

15 | } 16 | 17 |

Development Mode

18 |

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 |

24 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | using Microsoft.AspNetCore.Mvc.RazorPages; 3 | 4 | namespace sqRazorSample.Pages 5 | { 6 | public class ErrorModel : PageModel 7 | { 8 | public string RequestId { get; set; } 9 | 10 | public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); 11 | 12 | public void OnGet() 13 | { 14 | RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Pages/ProcessPayment.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model ProcessPaymentModel 3 | @{ 4 | ViewData["Title"] = "Payment Processed"; 5 | } 6 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Pages/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - sqRazorSample 7 | @RenderSection("Styles", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | @RenderSection("Scripts", required: false) 13 | 14 | 15 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Pages/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using sqRazorSample 2 | @namespace sqRazorSample.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Pages/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/PaymentFormExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/csharp_payment/PaymentFormExample.png -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace sqRazorSample 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/appsettings.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "AppSettings": { 9 | "Environment": "sandbox or production", 10 | "ApplicationId": "your-application-id", 11 | "AccessToken": "your-access-token", 12 | "LocationId": "your-location-id" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/bundleconfig.json: -------------------------------------------------------------------------------- 1 | // Configure bundling and minification for the project. 2 | // More info at https://go.microsoft.com/fwlink/?LinkId=808241 3 | [ 4 | { 5 | "outputFileName": "wwwroot/css/site.min.css", 6 | // An array of relative input file paths. Globbing patterns supported 7 | "inputFiles": [ 8 | "wwwroot/css/site.css" 9 | ] 10 | }, 11 | { 12 | "outputFileName": "wwwroot/js/site.min.js", 13 | "inputFiles": [ 14 | "wwwroot/js/site.js" 15 | ], 16 | // Optionally specify minification options 17 | "minify": { 18 | "enabled": true, 19 | "renameLocals": true 20 | }, 21 | // Optionally generate .map file 22 | "sourceMap": false 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/csharp_payment/wwwroot/favicon.ico -------------------------------------------------------------------------------- /connect-examples/v2/csharp_payment/wwwroot/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/csharp_payment/wwwroot/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/csharp_payment/wwwroot/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/graphql-sample-app/.env: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/graphql-sample-app/.env -------------------------------------------------------------------------------- /connect-examples/v2/graphql-sample-app/.env.example: -------------------------------------------------------------------------------- 1 | LOCATION_ID= 2 | SQUARE_ACCESS_TOKEN=your-access-token -------------------------------------------------------------------------------- /connect-examples/v2/graphql-sample-app/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es2021": true, 6 | "node": true 7 | }, 8 | "extends": "eslint:recommended", 9 | "parserOptions": { 10 | "ecmaVersion": 12 11 | }, 12 | "rules": { 13 | "array-bracket-spacing": ["error", "always"], 14 | "indent": ["error", 2], 15 | "object-curly-spacing": ["error","always"], 16 | "no-unused-vars": ["warn"], 17 | "prefer-const": ["warn", { 18 | "destructuring": "any", 19 | "ignoreReadBeforeAssign": false 20 | }], 21 | "quotes": ["error", "double"], 22 | "sort-keys": ["error"] 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /connect-examples/v2/graphql-sample-app/.gitignore: -------------------------------------------------------------------------------- 1 | .env 2 | node_modules -------------------------------------------------------------------------------- /connect-examples/v2/java_catalog/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | target/ 3 | .classpath 4 | .settings/* 5 | .project 6 | .vscode/* 7 | -------------------------------------------------------------------------------- /connect-examples/v2/java_catalog/src/main/java/com/squareup/catalog/demo/example/clone/CloneCatalogException.java: -------------------------------------------------------------------------------- 1 | package com.squareup.catalog.demo.example.clone; 2 | 3 | /** 4 | * Exception thrown when cloning fails. 5 | */ 6 | class CloneCatalogException extends RuntimeException { 7 | CloneCatalogException() { 8 | super(); 9 | } 10 | 11 | CloneCatalogException(Throwable t) { 12 | super(t); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /connect-examples/v2/java_catalog/src/main/java/com/squareup/catalog/demo/util/CatalogObjectTypes.java: -------------------------------------------------------------------------------- 1 | package com.squareup.catalog.demo.util; 2 | 3 | import com.squareup.square.models.CatalogObject; 4 | 5 | /** 6 | * Utility enum to capture different {@link CatalogObject} types. 7 | */ 8 | public enum CatalogObjectTypes { 9 | ITEM, 10 | ITEM_VARIATION, 11 | CATEGORY, 12 | TAX, 13 | DISCOUNT, 14 | MODIFIER, 15 | MODIFIER_LIST, 16 | IMAGE; 17 | } 18 | -------------------------------------------------------------------------------- /connect-examples/v2/java_catalog/src/main/java/com/squareup/catalog/demo/util/DiscountTypes.java: -------------------------------------------------------------------------------- 1 | package com.squareup.catalog.demo.util; 2 | 3 | import com.squareup.square.models.CatalogDiscount; 4 | 5 | /** 6 | * Utility enum to capture different {@link CatalogDiscount} types. 7 | */ 8 | public enum DiscountTypes { 9 | FIXED_AMOUNT, 10 | FIXED_PERCENTAGE, 11 | VARIABLE_AMOUNT, 12 | VARIABLE_PERCENTAGE; 13 | } 14 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | bin/ 3 | .settings/ 4 | .classpath 5 | .project 6 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/PaymentFormExampleJava.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/java_payment/PaymentFormExampleJava.png -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/Procfile: -------------------------------------------------------------------------------- 1 | web: java -jar target/connect-v2-payment-example-1.0.jar 2 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Square Payment Form Example App", 3 | "description": "A simple Java app to demonstrate Square's E-commerce API.", 4 | "addons": [] 5 | } 6 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/src/main/java/com/squareup/connectexamples/ecommerce/PaymentResult.java: -------------------------------------------------------------------------------- 1 | package com.squareup.connectexamples.ecommerce; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * PaymentResult is an object representing the response back to the front end. 7 | */ 8 | public class PaymentResult { 9 | 10 | private String title; 11 | 12 | private List errors; 13 | 14 | public PaymentResult(String t, List errorMessages) { 15 | this.title = t; 16 | this.errors = errorMessages; 17 | } 18 | 19 | public void setTitle(String title) { 20 | this.title = title; 21 | } 22 | 23 | public String getTitle() { 24 | return this.title; 25 | } 26 | 27 | public void setErrors(List errors) { 28 | this.errors = errors; 29 | } 30 | 31 | public List getErrors() { 32 | return this.errors; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/src/main/java/com/squareup/connectexamples/ecommerce/TokenWrapper.java: -------------------------------------------------------------------------------- 1 | package com.squareup.connectexamples.ecommerce; 2 | 3 | /** 4 | * TokenWrapper is a model object representing the token received from the front end. 5 | */ 6 | public class TokenWrapper { 7 | 8 | private String token; 9 | private String idempotencyKey; 10 | 11 | public String getToken() { 12 | return token; 13 | } 14 | 15 | public void setToken(String token) { 16 | this.token = token; 17 | } 18 | 19 | public String getIdempotencyKey() { 20 | return idempotencyKey; 21 | } 22 | 23 | public void setIdempotencyKey(String idempotencyKey) { 24 | this.idempotencyKey = idempotencyKey; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.thymeleaf.mode=HTML 2 | 3 | logging.level.org.springframework=INFO 4 | 5 | spring.profiles.active=production 6 | 7 | server.port=${PORT:3000} 8 | -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/src/main/resources/public/.well-known/apple-developer-merchantid-domain-association: -------------------------------------------------------------------------------- 1 | REPLACE_ME -------------------------------------------------------------------------------- /connect-examples/v2/java_payment/src/main/resources/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/java_payment/src/main/resources/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/java_payment/system.properties: -------------------------------------------------------------------------------- 1 | java.runtime.version=1.8 -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/.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 | SQ_ACCESS_TOKEN=your-access-token 6 | SQ_LOCATION_ID=your-location-id 7 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "commonjs": true, 5 | "es2021": true, 6 | "node": true 7 | }, 8 | "extends": "eslint:recommended", 9 | "parserOptions": { 10 | "ecmaVersion": 12 11 | }, 12 | "rules": { 13 | "array-bracket-spacing": ["error", "always"], 14 | "indent": ["error", 2], 15 | "object-curly-spacing": ["error","always"], 16 | "no-unused-vars": ["warn"], 17 | "prefer-const": ["warn", { 18 | "destructuring": "any", 19 | "ignoreReadBeforeAssign": false 20 | }], 21 | "quotes": ["error", "double"], 22 | "semi": ["error"], 23 | "sort-keys": ["error"] 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/cancel-booking-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/cancel-booking-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/confirmation-page-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/confirmation-page-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/contact-details-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/contact-details-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/modify-booking-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/modify-booking-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/select-availability-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/select-availability-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/select-services-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/select-services-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/bin/images/select-staff-screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_bookings/bin/images/select-staff-screenshot.png -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bookings-api-sample-app", 3 | "version": "1.0.0", 4 | "description": "A sample app demonstrating use of Square Bookings API", 5 | "main": "app.js", 6 | "private": true, 7 | "scripts": { 8 | "seed": "node ./bin/script/seed-data.js generate", 9 | "clear": "node ./bin/script/seed-data.js clear", 10 | "start": "nodemon -e js ./bin/www" 11 | }, 12 | "author": "barakj, emmac, azlee", 13 | "license": "Apache-2.0", 14 | "engines": { 15 | "node": ">=10" 16 | }, 17 | "dependencies": { 18 | "body-parser": "^1.19.0", 19 | "commander": "^7.2.0", 20 | "cookie-parser": "^1.4.5", 21 | "dotenv": "^10.0.0", 22 | "ejs": "^3.1.6", 23 | "express": "^4.17.1", 24 | "morgan": "^1.10.0", 25 | "nodemon": "^2.0.7", 26 | "readline": "^1.3.0", 27 | "square": "^33.0.0" 28 | }, 29 | "devDependencies": { 30 | "eslint": "^7.29.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/back-arrow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/blank-logo-sm.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/blank-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/plus.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/side-caret-selected.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/side-caret.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/public/images/success.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/views/pages/formatted-error.ejs: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | <%- include("../partials/header") %> 10 |
11 | 12 |
13 |

HTTP <%= code %>

14 |

<%= shortDescription %>

15 |

<%= description %>

16 | Back to Home 17 |
18 | 19 | 20 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/views/pages/reschedule.ejs: -------------------------------------------------------------------------------- 1 | <% include("../functions") %> 2 | 3 | 4 | 5 | 6 | 7 |
8 | <%- include("../partials/header") %> 9 |
10 |
11 |
12 | Back to booking 13 |
14 |
15 |
16 |
17 | Reschedule Appointment 18 | 19 |
20 |
21 |
22 |
23 |
24 |
25 | <%- include('../partials/date-selector', { availabilities }); %> 26 |
27 |
28 | 29 | -------------------------------------------------------------------------------- /connect-examples/v2/node_bookings/views/partials/header.ejs: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | server/node_modules 5 | app/node_modules 6 | /.pnp 7 | .pnp.js 8 | 9 | # testing 10 | /coverage 11 | 12 | # production 13 | app/build 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | 26 | server/node_modules 27 | server/.env 28 | 29 | app/.env -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/.env.example: -------------------------------------------------------------------------------- 1 | REACT_APP_SQUARE_APP_ID=your_application_id 2 | 3 | # Open issue with CRA https://github.com/facebook/create-react-app/pull/11752 4 | # include this in .env to ignore unwanted warnings 5 | GENERATE_SOURCEMAP=false -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | import pluginReactConfig from "eslint-plugin-react/configs/recommended.js"; 5 | 6 | 7 | export default [ 8 | {languageOptions: { globals: globals.browser }}, 9 | pluginJs.configs.recommended, 10 | ...tseslint.configs.recommended, 11 | pluginReactConfig, 12 | ]; -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/app/public/favicon.ico -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/app/public/logo192.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/app/public/logo512.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/components/CreditCardGroup/index.tsx: -------------------------------------------------------------------------------- 1 | import { useContext } from "react"; 2 | import { AppContext } from "../../context/AppContext"; 3 | import CardsOnFile from "./CardsOnFile"; 4 | import NewCreditCardInput from "./NewCreditCardInput"; 5 | import ComponentLayout from "../ComponentLayout"; 6 | 7 | interface CreditCardGroupProps {} 8 | 9 | const CreditCardGroup: React.FC = () => { 10 | const { selectedCustomer } = useContext(AppContext); 11 | return ( 12 | 13 | {selectedCustomer?.cards?.length ? ( 14 |
15 | 16 |

OR

17 | 18 |
19 | ) : ( 20 |
21 | 22 |
23 | )} 24 |
25 | ); 26 | }; 27 | 28 | export default CreditCardGroup; 29 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/components/HelperComponents/Status/index.tsx: -------------------------------------------------------------------------------- 1 | export const Status = ({ status }: { status: string }) => { 2 | switch (status) { 3 | case "ACTIVE": 4 | return Active; 5 | case "CANCELED": 6 | return Canceled; 7 | case "PAUSED": 8 | return Paused; 9 | default: 10 | return Unknown; 11 | } 12 | }; 13 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | body { 6 | margin: 0; 7 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 8 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 9 | sans-serif; 10 | -webkit-font-smoothing: antialiased; 11 | -moz-osx-font-smoothing: grayscale; 12 | } 13 | 14 | code { 15 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 16 | monospace; 17 | } 18 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | import "./index.css"; 4 | import App from "./App"; 5 | import reportWebVitals from "./reportWebVitals"; 6 | 7 | const root = ReactDOM.createRoot( 8 | document.getElementById("root") as HTMLElement, 9 | ); 10 | root.render( 11 | 12 | 13 | , 14 | ); 15 | 16 | // If you want to start measuring performance in your app, pass a function 17 | // to log results (for example: reportWebVitals(console.log)) 18 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 19 | reportWebVitals(); 20 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from "web-vitals"; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import("web-vitals").then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import "@testing-library/jest-dom"; 6 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/utils/apiQueries.ts: -------------------------------------------------------------------------------- 1 | // Functions that are used to query our express API for data 2 | 3 | export const FetchCustomer = async ({ customerId }: { customerId: string }) => { 4 | try { 5 | const response = await fetch(`/customers/${customerId}`); 6 | return await response.json(); 7 | } catch (error) { 8 | console.error("Error fetching customer data:", error); 9 | } 10 | }; 11 | 12 | export const FetchSubscriptions = async ({ 13 | customerId, 14 | }: { 15 | customerId: string; 16 | }) => { 17 | try { 18 | const response = await fetch("/subscriptions/search", { 19 | method: "POST", 20 | headers: { 21 | "Content-Type": "application/json", 22 | }, 23 | body: JSON.stringify({ 24 | customerId: customerId, 25 | }), 26 | }); 27 | return await response.json(); 28 | } catch (error) { 29 | console.error("Error fetching customer data:", error); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/src/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | export const formattedDate = (dateString: string) => { 2 | const date = new Date(dateString).toUTCString(); 3 | const [day, month, dayNum, year] = date.split(" "); 4 | return `${day} ${dayNum} ${month} ${year}`; 5 | }; 6 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: [ 4 | './src/**/*.{js,jsx,ts,tsx}', 5 | 'node_modules/flowbite-react/lib/esm/**/*.js' 6 | ], 7 | theme: { 8 | extend: {}, 9 | }, 10 | plugins: [ 11 | require('flowbite/plugin') 12 | ], 13 | } 14 | 15 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/.env.example: -------------------------------------------------------------------------------- 1 | SQ_ACCESS_TOKEN=yourAccessToken -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/autumn-soup@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/autumn-soup@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/avocado-toast@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/avocado-toast@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/bacon-burger@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/bacon-burger@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/bbq-chicken-pizza@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/bbq-chicken-pizza@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/caprese-salad@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/caprese-salad@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/chicken-caesar-wrap@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/chicken-caesar-wrap@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/chicken-sandwich@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/chicken-sandwich@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/egg-sunnyside-up-on-toast@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/egg-sunnyside-up-on-toast@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/grilled-steak@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/grilled-steak@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/italian-sandwich@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/italian-sandwich@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/meatballs@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/meatballs@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/mediterranean-yogurt-bowl@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/mediterranean-yogurt-bowl@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/oatmeal-with-fruit@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/oatmeal-with-fruit@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/pancakes-with-fruit@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/pancakes-with-fruit@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/pesto-pasta@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/pesto-pasta@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/salmon-with-zucchini@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/salmon-with-zucchini@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/steak-tacos@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/steak-tacos@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/strawberry-smoothie@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/strawberry-smoothie@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/vegetarian-pizza@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/vegetarian-pizza@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/vegetarian-wrap@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/vegetarian-wrap@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/bin/script/img/veggie-delight-salad@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_catalog_subscription/server/bin/script/img/veggie-delight-salad@2x.png -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/eslint.config.mjs: -------------------------------------------------------------------------------- 1 | import globals from "globals"; 2 | import pluginJs from "@eslint/js"; 3 | import tseslint from "typescript-eslint"; 4 | 5 | export default [ 6 | { languageOptions: { globals: globals.node } }, 7 | pluginJs.configs.recommended, 8 | ...tseslint.configs.recommended, 9 | 10 | // Add TypeScript parser 11 | { parser: "@typescript-eslint/parser" }, 12 | 13 | // Add TypeScript rules to allow non-strict null checks 14 | { 15 | files: ["*.ts", "*.tsx"], 16 | rules: { 17 | // Allow optional chaining 18 | "@typescript-eslint/prefer-optional-chain": "off", 19 | 20 | // Allow nullish coalescing 21 | "@typescript-eslint/prefer-nullish-coalescing": "off" 22 | } 23 | } 24 | ]; 25 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/index.ts: -------------------------------------------------------------------------------- 1 | // src/app.ts 2 | 3 | import express from "express"; 4 | 5 | import customerRoutes from "./routes/customers"; 6 | import subscriptionRoutes from "./routes/subscriptions"; 7 | import catalogRoutes from "./routes/catalog"; 8 | import cardRoutes from "./routes/cards"; 9 | import invoiceRoutes from "./routes/invoices"; 10 | 11 | // for TypeScript & Square serialization issue 12 | (BigInt.prototype as any).toJSON = function () { 13 | return this.toString(); 14 | }; 15 | 16 | const app = express(); 17 | app.use(express.json()); 18 | 19 | app.use("/customers", customerRoutes); 20 | app.use("/subscriptions", subscriptionRoutes); 21 | app.use("/catalog", catalogRoutes); 22 | app.use("/cards", cardRoutes); 23 | app.use("/invoices", invoiceRoutes); 24 | 25 | const PORT = process.env.PORT || 4000; 26 | 27 | app.listen(PORT, () => { 28 | console.log(`Server is running on http://localhost:${PORT}`); 29 | }); 30 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/routes/invoices.ts: -------------------------------------------------------------------------------- 1 | import express, { Request, Response } from "express"; 2 | import squareClient from "../square-client"; 3 | 4 | const router = express.Router(); 5 | 6 | // Fetches invoices based on the invoice IDs provided in the request body 7 | router.post("/", async (req: Request, res: Response) => { 8 | const { invoiceIds } = req.body; 9 | if (!invoiceIds) { 10 | res.status(400).json({ error: "invoiceIds is required" }); 11 | return; 12 | } 13 | 14 | // for each invoiceId, get the invoice 15 | const invoices = []; 16 | for (const invoiceId of invoiceIds) { 17 | try { 18 | const { 19 | result: { invoice }, 20 | } = await squareClient.invoicesApi.getInvoice(invoiceId.toString()); 21 | invoices.push(invoice); 22 | } catch (error) { 23 | console.error("Error fetching invoice:", error); 24 | res.status(500).json({ error: "Internal Server Error" }); 25 | return; 26 | } 27 | } 28 | res.json(invoices); 29 | }); 30 | 31 | export default router; 32 | -------------------------------------------------------------------------------- /connect-examples/v2/node_catalog_subscription/server/square-client/index.ts: -------------------------------------------------------------------------------- 1 | // src/squareClient.ts 2 | 3 | import * as Square from "square"; 4 | import dotenv from "dotenv"; 5 | 6 | dotenv.config(); 7 | 8 | const squareAccessToken = process.env.SQ_ACCESS_TOKEN as string; 9 | 10 | const squareClient = new Square.Client({ 11 | bearerAuthCredentials: { 12 | accessToken: squareAccessToken, 13 | }, 14 | environment: Square.Environment.Sandbox, 15 | }); 16 | 17 | export default squareClient; 18 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/.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 | SQ_APPLICATION_ID=your-application-id 6 | SQ_ACCESS_TOKEN=your-access-token 7 | SQ_LOCATION_ID=your-location-id -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true 5 | }, 6 | "extends": "eslint:recommended", 7 | "parserOptions": { 8 | "ecmaVersion": 12, 9 | "sourceType": "module" 10 | }, 11 | "rules": { 12 | "no-unused-vars": "off" 13 | }, 14 | "globals": { 15 | "process": true, 16 | "require": true, 17 | "module": true, 18 | "bwipjs": true 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-10.png -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-20.png -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-30.png -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_gift-cards/bin/images/gift-cards-api-app-40.png -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gift-card-api-sample-app", 3 | "version": "1.0.0", 4 | "description": "A sample app demonstrating use of Square Gift Card API", 5 | "main": "app.js", 6 | "private": true, 7 | "scripts": { 8 | "start": "nodemon -e js ./bin/www" 9 | }, 10 | "keywords": [ 11 | "gift", 12 | "cards", 13 | "sample", 14 | "app" 15 | ], 16 | "author": "barakj, emmac", 17 | "license": "Apache-2.0", 18 | "dependencies": { 19 | "@faker-js/faker": "^8.3.1", 20 | "body-parser": "^1.19.0", 21 | "cookie-parser": "^1.4.5", 22 | "dotenv": "^16.3.1", 23 | "ejs": "^3.1.6", 24 | "express": "^4.18.2", 25 | "express-session": "^1.17.3", 26 | "morgan": "^1.10.0", 27 | "nodemon": "^2.0.7", 28 | "square": "^33.0.0" 29 | }, 30 | "devDependencies": { 31 | "eslint": "^7.28.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/amex.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/caret.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/ellipsis.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/giftCardImage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/node_gift-cards/public/images/giftCardImage.png -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/left-arrow.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/loading.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/profile.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/selected.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/images/success.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/js/generate-barcode.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains functionality to create a Square gift card barcode based on the gan. 3 | * This barcode can be used for redeeming gift cards at Square POS. 4 | */ 5 | 6 | function generateBarCode(elementId, value) { 7 | const squareGiftCardBarcodeId = "sqgc://" + value; 8 | let canvas = document.createElement('canvas'); 9 | let options = { 10 | bcid: 'pdf417', // Barcode type 11 | text: squareGiftCardBarcodeId, // Text to encode 12 | scale: 2, // 3x scaling factor 13 | height: 10, // Bar height, in millimeters 14 | includetext: true, // Show human-readable text 15 | textxalign: 'center', // Always good to set this 16 | } 17 | bwipjs.toCanvas(canvas, options); 18 | document.getElementById(elementId).src = canvas.toDataURL('image/png'); 19 | } 20 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/js/loading.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains code to create the loading screen as part of the `reset` functionality. 3 | */ 4 | 5 | function createLoadingScreen(formElementId) { 6 | // Submit the form. 7 | document.getElementById(formElementId).submit(); 8 | 9 | // Create the loading screen by exposing the screen and shading the background. 10 | document.getElementsByClassName('loading__shadow-overlay')[0].style.display='flex'; 11 | } 12 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/public/js/pretty-dropdown-menu.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This file contains functions that handles the actions of the drop down menu 3 | */ 4 | 5 | function showMenuOptions() { 6 | document.querySelector(".pretty-dropdown-menu__list").classList.toggle("show"); 7 | } 8 | 9 | window.onclick = function (event) { 10 | var parentNode = event.target.closest(".pretty-dropdown-menu"); 11 | 12 | if (!parentNode) { 13 | var openDropdown = document.querySelector(".pretty-dropdown-menu__list"); 14 | if (openDropdown.classList.contains("show")) { 15 | openDropdown.classList.remove("show"); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/views/pages/error.ejs: -------------------------------------------------------------------------------- 1 | <%= status %> 2 |
3 | <%= message %> 4 |
5 | <%= error %> -------------------------------------------------------------------------------- /connect-examples/v2/node_gift-cards/views/partials/header.ejs: -------------------------------------------------------------------------------- 1 | <% include("../functions") %> 2 |
3 | <% if (typeof link != "undefined") { %> 4 | 12 | <% } else { %> 13 | Gift Card Dashboard 14 | <% }; %> 15 |
16 | <%= getCustomerName(customerGivenName, customerFamilyName, -1) %> 17 | 18 |
19 | 20 |
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 |
2 |
3 |

Customize your Online Store cursor

4 |

Connect your Square Account

5 |
6 | Connect 7 |
-------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | load File.expand_path("spring", __dir__) 3 | APP_PATH = File.expand_path('../config/application', __dir__) 4 | require_relative "../config/boot" 5 | require "rails/commands" 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | load File.expand_path("spring", __dir__) 3 | require_relative "../config/boot" 4 | require "rake" 5 | Rake.application.run 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require "fileutils" 3 | 4 | # path to your application root. 5 | APP_ROOT = File.expand_path('..', __dir__) 6 | 7 | def system!(*args) 8 | system(*args) || abort("\n== Command #{args} failed ==") 9 | end 10 | 11 | FileUtils.chdir APP_ROOT do 12 | # This script is a way to set up or update your development environment automatically. 13 | # This script is idempotent, so that you can run it at any time and get an expectable outcome. 14 | # Add necessary setup steps to this file. 15 | 16 | puts '== Installing dependencies ==' 17 | system! 'gem install bundler --conservative' 18 | system('bundle check') || system!('bundle install') 19 | 20 | # Install JavaScript dependencies 21 | system! 'bin/yarn' 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system! 'bin/rails log:clear tmp:clear' 25 | 26 | puts "\n== Restarting application server ==" 27 | system! 'bin/rails restart' 28 | end 29 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/spring: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | if !defined?(Spring) && [nil, "development", "test"].include?(ENV["RAILS_ENV"]) 3 | gem "bundler" 4 | require "bundler" 5 | 6 | # Load Spring without loading other gems in the Gemfile, for speed. 7 | Bundler.locked_gems&.specs&.find { |spec| spec.name == "spring" }&.tap do |spring| 8 | Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path 9 | gem "spring", spring.version 10 | require "spring/binstub" 11 | rescue Gem::LoadError 12 | # Ignore when Spring is not installed. 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/webpack: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" 4 | ENV["NODE_ENV"] ||= "development" 5 | 6 | require "pathname" 7 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 8 | Pathname.new(__FILE__).realpath) 9 | 10 | require "bundler/setup" 11 | 12 | require "webpacker" 13 | require "webpacker/webpack_runner" 14 | 15 | APP_ROOT = File.expand_path("..", __dir__) 16 | Dir.chdir(APP_ROOT) do 17 | Webpacker::WebpackRunner.run(ARGV) 18 | end 19 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/webpack-dev-server: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development" 4 | ENV["NODE_ENV"] ||= "development" 5 | 6 | require "pathname" 7 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 8 | Pathname.new(__FILE__).realpath) 9 | 10 | require "bundler/setup" 11 | 12 | require "webpacker" 13 | require "webpacker/dev_server_runner" 14 | 15 | APP_ROOT = File.expand_path("..", __dir__) 16 | Dir.chdir(APP_ROOT) do 17 | Webpacker::DevServerRunner.run(ARGV) 18 | end 19 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/bin/yarn: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_ROOT = File.expand_path('..', __dir__) 3 | Dir.chdir(APP_ROOT) do 4 | yarn = ENV["PATH"].split(File::PATH_SEPARATOR). 5 | select { |dir| File.expand_path(dir) != __dir__ }. 6 | product(["yarn", "yarn.cmd", "yarn.ps1"]). 7 | map { |dir, file| File.expand_path(file, dir) }. 8 | find { |file| File.executable?(file) } 9 | 10 | if yarn 11 | exec yarn, *ARGV 12 | else 13 | $stderr.puts "Yarn executable was not detected in the system." 14 | $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" 15 | exit 1 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require_relative "config/environment" 4 | 5 | run Rails.application 6 | Rails.application.load_server 7 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) 2 | 3 | require "bundler/setup" # Set up gems listed in the Gemfile. 4 | require "bootsnap/setup" # Speed up boot time by caching expensive operations. 5 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/cable.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: async 3 | 4 | test: 5 | adapter: test 6 | 7 | production: 8 | adapter: redis 9 | url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %> 10 | channel_prefix: snippet_sample_production 11 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/credentials.yml.enc: -------------------------------------------------------------------------------- 1 | xFZmsyhsKdgbsWgQoueHMW5dOVKKnzp2dFokRD1ZtUr8b9YtgRfLC8HRV//mylNI1QB/n/2SRt8QRl8f4Xl7wKmSIjVMOe3Yg3Zzms6dJuact4qQxdyXuFDquYSEON6dYL4VZ1QMWxhKfdwfmPu3tygQV/1PpjNizfwY+bYfaa8neECxa90cfoKqlogY64cZ4kZDUB3T6PX7/aFNI5S/5xuXoQzeGxVkMROYhhsdajcdjfMbtsWAuzV4/qEkhYVH+id0Y0JbT2pU20Xs0IMzS8dtH7GXYss73Js83dwqZpEqN9l5F6VlhJkDhIOL7vsGe+QS6q6rZZlKZG3pVZepdyHDQGYU/HIwkL2ZH9DC6wlNccoSEIHKGqwCp4qXuSCO/1u7cloWr4sNPp/ncY/tqOJJDqh0GYNnQajF--a9sgbQSb9lHDmKtW--XbzkbORIrwlflOL9vBli0Q== -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require_relative "application" 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/initializers/application_controller_renderer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # ActiveSupport::Reloader.to_prepare do 4 | # ApplicationController.renderer.defaults.merge!( 5 | # http_host: 'example.org', 6 | # https: false 7 | # ) 8 | # end 9 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/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 | # Add Yarn node_modules folder to the asset load path. 9 | Rails.application.config.assets.paths << Rails.root.join('node_modules') 10 | 11 | # Precompile additional assets. 12 | # application.js, application.css, and all non-JS/CSS in the app/assets 13 | # folder are already added. 14 | # Rails.application.config.assets.precompile += %w( admin.js admin.css ) 15 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/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| /my_noisy_library/.match?(line) } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code 7 | # by setting BACKTRACE=1 before calling your invocation, like "BACKTRACE=1 ./bin/rails runner 'MyClass.perform'". 8 | Rails.backtrace_cleaner.remove_silencers! if ENV["BACKTRACE"] 9 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Specify a serializer for the signed and encrypted cookie jars. 4 | # Valid options are :json, :marshal, and :hybrid. 5 | Rails.application.config.action_dispatch.cookies_serializer = :json 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/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 += [ 5 | :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn 6 | ] 7 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/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_snippet/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_snippet/config/initializers/omniauth.rb: -------------------------------------------------------------------------------- 1 | Rails.application.config.middleware.use OmniAuth::Builder do 2 | provider :square, ENV['SQUARE_APPLICATION_ID'], ENV['SQUARE_APPLICATION_SECRET'], 3 | { 4 | :connect_site => 'https://connect.squareup.com', 5 | :scope => 'ONLINE_STORE_SITE_READ ONLINE_STORE_SNIPPETS_READ ONLINE_STORE_SNIPPETS_WRITE MERCHANT_PROFILE_READ EMPLOYEES_READ MERCHANT_PROFILE_WRITE' 6 | } 7 | end 8 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/initializers/permissions_policy.rb: -------------------------------------------------------------------------------- 1 | # Define an application-wide HTTP permissions policy. For further 2 | # information see https://developers.google.com/web/updates/2018/06/feature-policy 3 | # 4 | # Rails.application.config.permissions_policy do |f| 5 | # f.camera :none 6 | # f.gyroscope :none 7 | # f.microphone :none 8 | # f.usb :none 9 | # f.fullscreen :self 10 | # f.payment :self, "https://secure.example.com" 11 | # end 12 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/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] 9 | end 10 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/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 | # The following keys must be escaped otherwise they will not be retrieved by 20 | # the default I18n backend: 21 | # 22 | # true, false, on, off, yes, no 23 | # 24 | # Instead, surround them with single quotes. 25 | # 26 | # en: 27 | # 'true': 'foo' 28 | # 29 | # To learn more, please read the Rails Internationalization guide 30 | # available at https://guides.rubyonrails.org/i18n.html. 31 | 32 | en: 33 | hello: "Hello world" 34 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html 3 | get "/", to: "welcome#index", as: 'welcome' 4 | get '/auth/:provider/callback', to: 'sessions#create' 5 | resources :sites, only: [:index, :show] do 6 | resources :snippets, only: [:create, :destroy] 7 | end 8 | 9 | end 10 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/spring.rb: -------------------------------------------------------------------------------- 1 | Spring.watch( 2 | ".ruby-version", 3 | ".rbenv-vars", 4 | "tmp/restart.txt", 5 | "tmp/caching-dev.txt" 6 | ) 7 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/webpack/development.js: -------------------------------------------------------------------------------- 1 | process.env.NODE_ENV = process.env.NODE_ENV || 'development' 2 | 3 | const environment = require('./environment') 4 | 5 | module.exports = environment.toWebpackConfig() 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/webpack/environment.js: -------------------------------------------------------------------------------- 1 | const { environment } = require('@rails/webpacker') 2 | 3 | module.exports = environment 4 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/webpack/production.js: -------------------------------------------------------------------------------- 1 | process.env.NODE_ENV = process.env.NODE_ENV || 'production' 2 | 3 | const environment = require('./environment') 4 | 5 | module.exports = environment.toWebpackConfig() 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/config/webpack/test.js: -------------------------------------------------------------------------------- 1 | process.env.NODE_ENV = process.env.NODE_ENV || 'development' 2 | 3 | const environment = require('./environment') 4 | 5 | module.exports = environment.toWebpackConfig() 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.3" 2 | services: 3 | web: 4 | build: . 5 | command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'" 6 | volumes: 7 | - .:/snippet_sample 8 | ports: 9 | - "3000:3000" -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | rm -f /snippet_sample/tmp/pids/server.pid 4 | exec "$@" -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/lib/assets/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/lib/tasks/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/lib/tasks/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/log/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "snippet-sample", 3 | "private": true, 4 | "dependencies": { 5 | "@rails/actioncable": "^6.0.0", 6 | "@rails/ujs": "^6.0.0", 7 | "@rails/webpacker": "5.2.1", 8 | "turbolinks": "^5.2.0" 9 | }, 10 | "version": "0.1.0", 11 | "devDependencies": { 12 | "webpack-dev-server": "^3.11.2" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: [ 3 | require('postcss-import'), 4 | require('postcss-flexbugs-fixes'), 5 | require('postcss-preset-env')({ 6 | autoprefixer: { 7 | flexbox: 'no-2009' 8 | }, 9 | stage: 3 10 | }) 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/public/apple-touch-icon-precomposed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/public/apple-touch-icon-precomposed.png -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/public/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/public/apple-touch-icon.png -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/public/favicon.ico -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file 2 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/application_system_test_case.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ApplicationSystemTestCase < ActionDispatch::SystemTestCase 4 | driven_by :selenium, using: :chrome, screen_size: [1400, 1400] 5 | end 6 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/channels/application_cable/connection_test.rb: -------------------------------------------------------------------------------- 1 | require "test_helper" 2 | 3 | class ApplicationCable::ConnectionTest < ActionCable::Connection::TestCase 4 | # test "connects with cookies" do 5 | # cookies.signed[:user_id] = 42 6 | # 7 | # connect 8 | # 9 | # assert_equal connection.user_id, "42" 10 | # end 11 | end 12 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/controllers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/controllers/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/fixtures/files/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/fixtures/files/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/helpers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/helpers/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/integration/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/integration/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/mailers/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/models/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/system/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/test/system/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV['RAILS_ENV'] ||= 'test' 2 | require_relative "../config/environment" 3 | require "rails/test_help" 4 | 5 | class ActiveSupport::TestCase 6 | # Run tests in parallel with specified workers 7 | parallelize(workers: :number_of_processors) 8 | 9 | # Add more helper methods to be used by all tests here... 10 | end 11 | -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/tmp/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/tmp/.keep -------------------------------------------------------------------------------- /connect-examples/v2/rails_snippet/tmp/pids/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/rails_snippet/tmp/pids/.keep -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/.bowerrc: -------------------------------------------------------------------------------- 1 | { 2 | "directory": "wwwroot/lib" 3 | } 4 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/.gitignore: -------------------------------------------------------------------------------- 1 | # Autosave files 2 | *~ 3 | 4 | # build 5 | [Oo]bj/ 6 | [Bb]in/ 7 | packages/ 8 | TestResults/ 9 | 10 | # globs 11 | Makefile.in 12 | *.DS_Store 13 | *.sln.cache 14 | *.suo 15 | *.cache 16 | *.pidb 17 | *.userprefs 18 | *.usertasks 19 | config.log 20 | config.make 21 | config.status 22 | aclocal.m4 23 | install-sh 24 | autom4te.cache/ 25 | *.user 26 | *.tar.gz 27 | tarballs/ 28 | test-results/ 29 | Thumbs.db 30 | .vs/ 31 | 32 | # Mac bundle stuff 33 | *.dmg 34 | *.app 35 | 36 | # resharper 37 | *_Resharper.* 38 | *.Resharper 39 | 40 | # dotCover 41 | *.dotCover 42 | 43 | appsettings.json 44 | appsettings.*.json 45 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/Checkout.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model CheckoutModel 3 | @{ 4 | } -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/Error.cshtml: -------------------------------------------------------------------------------- 1 | @page 2 | @model ErrorModel 3 | @{ 4 | ViewData["Title"] = "Error"; 5 | } 6 | 7 |

@Model.ErrorMessage

8 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/Error.cshtml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Mvc.RazorPages; 2 | 3 | namespace csharp_checkout.Pages 4 | { 5 | public class ErrorModel : PageModel 6 | { 7 | public string ErrorMessage { get; set; } 8 | 9 | public void OnGet(string error) 10 | { 11 | ErrorMessage = error; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/Index.cshtml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Mvc; 6 | using Microsoft.AspNetCore.Mvc.RazorPages; 7 | 8 | namespace csharp_checkout 9 | { 10 | public class IndexModel : PageModel 11 | { 12 | public void OnGet() 13 | { 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/_Layout.cshtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @ViewData["Title"] - csharp_checkout 7 | @RenderSection("Styles", required: false) 8 | 9 | 10 | @RenderBody() 11 | 12 | @RenderSection("Scripts", required: false) 13 | 14 | 15 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/_ViewImports.cshtml: -------------------------------------------------------------------------------- 1 | @using csharp_checkout 2 | @namespace csharp_checkout.Pages 3 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 4 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Pages/_ViewStart.cshtml: -------------------------------------------------------------------------------- 1 | @{ 2 | Layout = "_Layout"; 3 | } 4 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace csharp_checkout 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | BuildWebHost(args).Run(); 18 | } 19 | 20 | public static IWebHost BuildWebHost(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup() 23 | .Build(); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:32050/", 7 | "sslPort": 0 8 | } 9 | }, 10 | "profiles": { 11 | "IIS Express": { 12 | "commandName": "IISExpress", 13 | "launchBrowser": true, 14 | "environmentVariables": { 15 | "ASPNETCORE_ENVIRONMENT": "Development" 16 | } 17 | }, 18 | "Sandbox": { 19 | "commandName": "Project", 20 | "launchBrowser": true, 21 | "environmentVariables": { 22 | "ASPNETCORE_ENVIRONMENT": "Sandbox" 23 | }, 24 | "applicationUrl": "http://localhost:5000/" 25 | }, 26 | "Production": { 27 | "commandName": "Project", 28 | "launchBrowser": true, 29 | "environmentVariables": { 30 | "ASPNETCORE_ENVIRONMENT": "Production" 31 | }, 32 | "applicationUrl": "http://localhost:5000/" 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/appsettings.Production.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Warning" 6 | } 7 | }, 8 | "AppSettings": { 9 | "Environment": "production", 10 | "AccessToken": "prod_access_token", 11 | "LocationId": "prod_location_id" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/appsettings.Sandbox.json.example: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "IncludeScopes": false, 4 | "LogLevel": { 5 | "Default": "Debug", 6 | "System": "Information", 7 | "Microsoft": "Information" 8 | } 9 | }, 10 | "AppSettings": { 11 | "Environment": "sandbox", 12 | "AccessToken": "sandbox_access_token", 13 | "LocationId": "sandbox_location_id" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "asp.net", 3 | "private": true, 4 | "dependencies": { 5 | "bootstrap": "3.3.7", 6 | "jquery": "2.2.0", 7 | "jquery-validation": "1.14.0", 8 | "jquery-validation-unobtrusive": "3.2.6" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/bundleconfig.json: -------------------------------------------------------------------------------- 1 | // Configure bundling and minification for the project. 2 | // More info at https://go.microsoft.com/fwlink/?LinkId=808241 3 | [ 4 | { 5 | "outputFileName": "wwwroot/css/site.min.css", 6 | // An array of relative input file paths. Globbing patterns supported 7 | "inputFiles": [ 8 | "wwwroot/css/site.css" 9 | ] 10 | }, 11 | { 12 | "outputFileName": "wwwroot/js/site.min.js", 13 | "inputFiles": [ 14 | "wwwroot/js/site.js" 15 | ], 16 | // Optionally specify minification options 17 | "minify": { 18 | "enabled": true, 19 | "renameLocals": true 20 | }, 21 | // Optionally generate .map file 22 | "sourceMap": false 23 | } 24 | ] 25 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/checkout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/v2_deprecated/csharp_checkout/checkout.png -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/confirmation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/v2_deprecated/csharp_checkout/confirmation.png -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/csharp_checkout.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp_checkout", "csharp_checkout.csproj", "{A4F77D02-0839-44D2-AD83-41A0CC5A7A7D}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Any CPU = Debug|Any CPU 9 | Release|Any CPU = Release|Any CPU 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {A4F77D02-0839-44D2-AD83-41A0CC5A7A7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 13 | {A4F77D02-0839-44D2-AD83-41A0CC5A7A7D}.Debug|Any CPU.Build.0 = Debug|Any CPU 14 | {A4F77D02-0839-44D2-AD83-41A0CC5A7A7D}.Release|Any CPU.ActiveCfg = Release|Any CPU 15 | {A4F77D02-0839-44D2-AD83-41A0CC5A7A7D}.Release|Any CPU.Build.0 = Release|Any CPU 16 | EndGlobalSection 17 | EndGlobal 18 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/csharp_checkout/wwwroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/square/connect-api-examples/0f58813fc6e3b0db537291c349adb95e904d1cba/connect-examples/v2/v2_deprecated/csharp_checkout/wwwroot/favicon.ico -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/php_checkout/.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 8 | 9 | 10 | -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/php_checkout/.gitignore: -------------------------------------------------------------------------------- 1 | vendor/* 2 | tests/* 3 | .env -------------------------------------------------------------------------------- /connect-examples/v2/v2_deprecated/php_checkout/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "require": { 3 | "square/square": "18.0.0.20220420", 4 | "vlucas/phpdotenv": "^3.3" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /templates/README.md: -------------------------------------------------------------------------------- 1 | # Square Connect API Templates 2 | 3 | This directory contains code templates to simplify use of our SDKs and APIs. 4 | These templates are also referenced in setup guides at 5 | [developer.squareup.com/docs]. 6 | 7 | ## In this directory 8 | 9 | * `php` - server-side code templates in PHP 10 | * `web-ui` - client-side UI templates and themes for web-based SDKs 11 | 12 | -------------------------------------------------------------------------------- 13 | 14 | [//]: # "Link anchor definitions" 15 | [developer.squareup.com/docs]: https://developer.squareup.com/docs 16 | -------------------------------------------------------------------------------- /templates/web-ui/web-payments-sdk/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 | -------------------------------------------------------------------------------- /templates/web-ui/web-payments-sdk/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 | -------------------------------------------------------------------------------- /templates/web-ui/web-payments-sdk/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 | --------------------------------------------------------------------------------