Skip to content

Instantly share code, notes, and snippets.

@mootrichard
Created October 24, 2018 21:30
Show Gist options
  • Save mootrichard/e9de3495658a90dc11b46351f07263fc to your computer and use it in GitHub Desktop.
Save mootrichard/e9de3495658a90dc11b46351f07263fc to your computer and use it in GitHub Desktop.
Parent component for Square React Payment Form
import React, { Component } from 'react';
import './App.css';
import PaymentForm from './components/PaymentForm';
class App extends Component {
constructor(props){
super(props)
this.state = {
loaded: false
}
}
componentWillMount(){
const that = this;
let sqPaymentScript = document.createElement('script');
sqPaymentScript.src = "https://js.squareup.com/v2/paymentform";
sqPaymentScript.type = "text/javascript"
sqPaymentScript.async = false;
document.getElementsByTagName("head")[0].appendChild(sqPaymentScript);
sqPaymentScript.onload = ()=>{that.setState({
loaded: true
})};
}
render() {
return (
this.state.loaded &&
<PaymentForm
paymentForm={ window.SqPaymentForm }
/>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment