Skip to content

Commit

Permalink
Merge pull request #43 from manishkatyan/package-update
Browse files Browse the repository at this point in the history
fix:lint error
  • Loading branch information
nishekh-e-r authored Aug 3, 2022
2 parents 71846ae + bc54dbf commit ff674e6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 94 deletions.
79 changes: 26 additions & 53 deletions admin/src/components/ProductList/embedCodeModal.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import React, { useState } from "react";
import PropTypes from "prop-types";
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import {
ModalLayout,
ModalBody,
ModalHeader,
ModalFooter,
} from "@strapi/design-system/ModalLayout";
import { Typography } from "@strapi/design-system/Typography";
import { Button } from "@strapi/design-system/Button";
import { Flex } from "@strapi/design-system/Flex";
import { Box } from "@strapi/design-system/Box";
import {
Accordion,
AccordionToggle,
AccordionContent,
} from "@strapi/design-system/Accordion";
} from '@strapi/design-system/ModalLayout';
import { Typography } from '@strapi/design-system/Typography';
import { Button } from '@strapi/design-system/Button';
import { Flex } from '@strapi/design-system/Flex';
import { Box } from '@strapi/design-system/Box';
import { Accordion, AccordionToggle, AccordionContent } from '@strapi/design-system/Accordion';

import { stripeResponse, ProductRespone } from "./constant";
import { stripeResponse, ProductRespone } from './constant';

const EmbedCodeModal = ({
productId,
Expand Down Expand Up @@ -46,8 +42,8 @@ const EmbedCodeModal = ({
</Box>
<Box>
<Typography variant="omega">
Enable the Stripe Payment button in your frontend app by
following the simple steps mentioned below:
Enable the Stripe Payment button in your frontend app by following the simple
steps mentioned below:
</Typography>
</Box>
</Flex>
Expand All @@ -59,17 +55,12 @@ const EmbedCodeModal = ({
</Box>
<Box>
<Typography variant="epsilon">
Embed the script tag in the html header section of your
product list, payment success and payment failure pages:
Embed the script tag in the html header section of your product list, payment
success and payment failure pages:
</Typography>
</Box>
</Flex>
<Box
background="neutral100"
padding={2}
marginTop={4}
marginBottom={4}
>
<Box background="neutral100" padding={2} marginTop={4} marginBottom={4}>
<Typography>
{`
<script
Expand All @@ -87,23 +78,17 @@ const EmbedCodeModal = ({
</Box>
<Box>
<Typography variant="epsilon">
Show the “Buy Now” button next to your product details on the
product list page.
Show the “Buy Now” button next to your product details on the product list page.
</Typography>
</Box>
</Flex>
<Box
background="neutral100"
padding={2}
marginTop={4}
marginBottom={4}
>
<Box background="neutral100" padding={2} marginTop={4} marginBottom={4}>
<Typography>
{`
<button class="css style" type="button" class="SS_ProductCheckout" data-id="${productId}" data-url="${
window.location.origin
}">
${isSubscription ? "Subscribe" : "BuyNow"}
${isSubscription ? 'Subscribe' : 'BuyNow'}
</button>
`}
</Typography>
Expand All @@ -114,18 +99,12 @@ const EmbedCodeModal = ({
</Box>
<Box>
<Typography variant="epsilon">
Optionally, you can fetch product details such as title,
description, image and price from the API end-point mentioned
below and show them.
Optionally, you can fetch product details such as title, description, image and
price from the API end-point mentioned below and show them.
</Typography>
</Box>
</Flex>
<Box
background="neutral100"
padding={2}
marginTop={4}
marginBottom={4}
>
<Box background="neutral100" padding={2} marginTop={4} marginBottom={4}>
<Typography>
{`const response = await axios.get(
" ${window.location.origin}/strapi-stripe/getProduct/${productId}"
Expand All @@ -135,7 +114,7 @@ const EmbedCodeModal = ({
<Box padding={4} background="neutral100" marginBottom={4}>
<Accordion
expanded={expandProduct}
toggle={() => setExpandProduct((s) => !s)}
toggle={() => setExpandProduct(s => !s)}
id="acc-1"
size="S"
>
Expand All @@ -156,18 +135,12 @@ const EmbedCodeModal = ({
</Box>
<Box>
<Typography variant="epsilon">
Optionally, you can show payment transaction status and
details on your payment success (or error) page. Use the API
call mentioned below:
Optionally, you can show payment transaction status and details on your payment
success (or error) page. Use the API call mentioned below:
</Typography>
</Box>
</Flex>
<Box
background="neutral100"
padding={2}
marginTop={4}
marginBottom={4}
>
<Box background="neutral100" padding={2} marginTop={4} marginBottom={4}>
<Box>
<Typography>
{`
Expand All @@ -184,15 +157,15 @@ const EmbedCodeModal = ({
<Typography>
{`const response = await axios.get(${
window.location.origin
}/strapi-stripe/retrieveCheckoutSession/${"$"}{checkoutSessionId}
}/strapi-stripe/retrieveCheckoutSession/${'$'}{checkoutSessionId}
)
`}
</Typography>
</Box>
<Box padding={4} background="neutral100">
<Accordion
expanded={expandPayment}
toggle={() => setExpandPayment((s) => !s)}
toggle={() => setExpandPayment(s => !s)}
id="acc-1"
size="S"
>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"name": "strapi-stripe",
"version": "2.4.0",

"version": "2.4.1",

"description": "Online payments and subscriptions made simple, secure and fast.This free plugin enables you to accept online payments and create subscriptions using Credit Card, Apple pay and Google pay on your Strapi app via Stripe.",
"strapi": {
"name": "strapi-stripe",
Expand Down
73 changes: 35 additions & 38 deletions server/public/stripe.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
/* eslint-disable no-undef */
"use strict";
'use strict';

window.onload = () => {
// for product Checkout
const ssProduct = document.querySelectorAll(".SS_ProductCheckout");
const ssProduct = document.querySelectorAll('.SS_ProductCheckout');
if (ssProduct) {
ssProduct.forEach((product) => {
product.addEventListener("click", function handleClick(event) {
SS_ProductCheckout(
event.target?.dataset?.id,
event.target?.dataset?.url
);
ssProduct.forEach(product => {
product.addEventListener('click', function handleClick(event) {
SS_ProductCheckout(event.target.dataset.id, event.target.dataset.url);
});
});
}
// for storing product payment order in strapi
const params = new URLSearchParams(document.location.search);
const checkoutSessionId = params.get("sessionId");
const checkoutSessionId = params.get('sessionId');
if (checkoutSessionId) {
SS_GetProductPaymentDetails(checkoutSessionId);
}
Expand All @@ -25,35 +22,35 @@ window.onload = () => {
// product Checkout logic

function SS_ProductCheckout(productId, baseUrl) {
localStorage.setItem("strapiStripeUrl", baseUrl);
const getProductApi = baseUrl + "/strapi-stripe/getProduct/" + productId;
const checkoutSessionUrl = baseUrl + "/strapi-stripe/createCheckoutSession/";
localStorage.setItem('strapiStripeUrl', baseUrl);
const getProductApi = baseUrl + '/strapi-stripe/getProduct/' + productId;
const checkoutSessionUrl = baseUrl + '/strapi-stripe/createCheckoutSession/';

fetch(getProductApi, {
method: "get",
mode: "cors",
method: 'get',
mode: 'cors',
headers: new Headers({
"Content-Type": "application/json",
'Content-Type': 'application/json',
}),
})
.then((response) => response.json())
.then((response) => {
.then(response => response.json())
.then(response => {
fetch(checkoutSessionUrl, {
method: "post",
method: 'post',
body: JSON.stringify({
stripePriceId: response.stripePriceId,
stripePlanId: response.stripePlanId,
isSubscription: response.isSubscription,
productId: response.id,
productName: response.title,
}),
mode: "cors",
mode: 'cors',
headers: new Headers({
"Content-Type": "application/json",
'Content-Type': 'application/json',
}),
})
.then((response) => response.json())
.then((response) => {
.then(response => response.json())
.then(response => {
if (response.id) {
window.location.replace(response.url);
}
Expand All @@ -64,31 +61,31 @@ function SS_ProductCheckout(productId, baseUrl) {
// storing product payment order in strapi logic

function SS_GetProductPaymentDetails(checkoutSessionId) {
const baseUrl = localStorage.getItem("strapiStripeUrl");
const baseUrl = localStorage.getItem('strapiStripeUrl');
const retrieveCheckoutSessionUrl =
baseUrl + "/strapi-stripe/retrieveCheckoutSession/" + checkoutSessionId;
baseUrl + '/strapi-stripe/retrieveCheckoutSession/' + checkoutSessionId;
fetch(retrieveCheckoutSessionUrl, {
method: "get",
mode: "cors",
method: 'get',
mode: 'cors',
headers: new Headers({
"Content-Type": "application/json",
'Content-Type': 'application/json',
}),
})
.then((response) => response.json())
.then((response) => {
if (response.payment_status === "paid") {
.then(response => response.json())
.then(response => {
if (response.payment_status === 'paid') {
if (
window.performance
.getEntriesByType("navigation")
.map((nav) => nav.type)
.includes("reload")
.getEntriesByType('navigation')
.map(nav => nav.type)
.includes('reload')
) {
console.info("website reloded");
console.info('website reloded');
} else {
// store payment in strapi
const stripePaymentUrl = baseUrl + "/strapi-stripe/stripePayment";
const stripePaymentUrl = baseUrl + '/strapi-stripe/stripePayment';
fetch(stripePaymentUrl, {
method: "post",
method: 'post',
body: JSON.stringify({
txnDate: new Date(),
transactionId: response.id,
Expand All @@ -99,9 +96,9 @@ function SS_GetProductPaymentDetails(checkoutSessionId) {
customerEmail: response.customer_details.email,
stripeProduct: response.metadata.productId,
}),
mode: "cors",
mode: 'cors',
headers: new Headers({
"Content-Type": "application/json",
'Content-Type': 'application/json',
}),
});
}
Expand Down

0 comments on commit ff674e6

Please sign in to comment.