Created
October 24, 2018 21:30
-
-
Save mootrichard/e9de3495658a90dc11b46351f07263fc to your computer and use it in GitHub Desktop.
Parent component for Square React Payment Form
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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