Skip to content

Instantly share code, notes, and snippets.

@sadam1807
Last active October 30, 2019 16:03
Show Gist options
  • Save sadam1807/a024d7a56a0a4d0ebe7f369a654d3c3d to your computer and use it in GitHub Desktop.
Save sadam1807/a024d7a56a0a4d0ebe7f369a654d3c3d to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from 'react';
import './App.css';
import Square from './Component/Square';
const App = () => {
const [isLoad, setLoad] = useState(false);
useEffect(() => {
let sqPaymentScript = document.createElement("script");
// sandbox: https://js.squareupsandbox.com/v2/paymentform
// production: https://js.squareup.com/v2/paymentform
sqPaymentScript.src = "https://js.squareupsandbox.com/v2/paymentform";
sqPaymentScript.type = "text/javascript";
sqPaymentScript.async = false;
sqPaymentScript.onload = () => {
setLoad(true);
};
document.getElementsByTagName("head")[0].appendChild(sqPaymentScript);
});
const squarePayment = isLoad ? (
<Square paymentForm={ window.SqPaymentForm }/>
) : (
null
)
return (
<div className="App">
<h1>Square</h1>
{squarePayment}
</div>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment