├── .gitignore ├── .prettierignore ├── README.md ├── now.json ├── package.json ├── public ├── favicon.png ├── index.html └── manifest.json ├── src ├── App.js ├── App.test.js ├── img │ └── secured-by-paystack.png ├── index.css ├── index.js ├── logo.svg ├── serviceWorker.js └── style.css └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | /.pnp 4 | .pnp.js 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | banner image 2 |

3 | 4 | 5 | jsstandards 6 | 7 | 8 | jsstandards 9 | 10 | 11 | PRs welcome! 12 | 13 | 14 | PRs welcome! 15 | 16 |

17 | 18 | ## Usage 19 | 20 | Run locally: 21 | 22 | Clone 23 | ``` 24 | git clone https://github.com/Developerayo/paystack-payment.git 25 | ``` 26 | 27 | Move into the file with 28 | ``` 29 | cd paystack-payment 30 | ``` 31 | 32 | Then 33 | ``` 34 | yarn install 35 | ``` 36 | Start dev server 37 | 38 | ``` 39 | yarn start 40 | ``` 41 | now open https://localhost:3000. 42 | 43 | Testing with jest and standards 44 | 45 | ``` 46 | yarn test 47 | ``` 48 | 49 |
50 | Don't forget to drop a ⭐️ I certainly do not mind🙂 51 | -------------------------------------------------------------------------------- /now.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "name": "Paystack-Payment-demo", 4 | "alias": "paystack.now.sh", 5 | "builds": [ 6 | {"src": "package.json", "use": "@now/static-build", "config": {"distDir": "build"}} 7 | ], 8 | "routes": [ 9 | {"src": "/static/(.*)", "headers": {"cache-control": "s-maxage=31536000,immutable"}, "dest": "/static/$1"}, 10 | {"src": "/favicon.ico", "dest": "/favicon.ico"}, 11 | {"src": "/asset-manifest.json", "dest": "/asset-manifest.json"}, 12 | {"src": "/manifest.json", "dest": "/manifest.json"}, 13 | {"src": "/precache-manifest.(.*)", "dest": "/precache-manifest.$1"}, 14 | {"src": "/service-worker.js", "headers": {"cache-control": "s-maxage=0"}, "dest": "/service-worker.js"}, 15 | {"src": "/(.*)", "headers": {"cache-control": "s-maxage=0"}, "dest": "/index.html"} 16 | ] 17 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "paystack-pay-demo", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "paystack": "^2.0.1", 7 | "prettier": "^1.17.1", 8 | "react": "^16.8.6", 9 | "react-dom": "^16.8.6", 10 | "react-paystack": "^2.0.2", 11 | "react-scripts": "3.0.1", 12 | "standard": "^12.0.1" 13 | }, 14 | "scripts": { 15 | "start": "react-scripts start", 16 | "build": "react-scripts build", 17 | "test": "standard && react-scripts test", 18 | "eject": "react-scripts eject", 19 | "now-build": "react-scripts build", 20 | "now-dev": "gatsby develop -p $PORT" 21 | }, 22 | "eslintConfig": { 23 | "extends": "react-app" 24 | }, 25 | "browserslist": { 26 | "production": [ 27 | ">0.2%", 28 | "not dead", 29 | "not op_mini all" 30 | ], 31 | "development": [ 32 | "last 1 chrome version", 33 | "last 1 firefox version", 34 | "last 1 safari version" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /public/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developerayo/paystack-payment/b6d4b183924f893beab4033e666f064c20996ba3/public/favicon.png -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | Paystack Payment Demo 10 | 11 | 12 | 13 |
14 | 15 | 16 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "Paystack Payment", 3 | "name": "Paystack Payment", 4 | "icons": [ 5 | { 6 | "src": "favicon.png", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#08A4DA", 14 | "background_color": "#08A4DA" 15 | } 16 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import PaystackButton from 'react-paystack'; 3 | 4 | import secure from './img/secured-by-paystack.png'; 5 | import './style.css'; 6 | 7 | class App extends Component { 8 | 9 | state = { 10 | key: "pk_live_0c5b29b86d50a95c3d721c9e2e7e4f0aff7640dc", 11 | email: "shodipovi@gmail.com", 12 | amount: 10000 13 | } 14 | 15 | callback = (response) => { 16 | alert('success. transaction ref is ' + response.reference); 17 | } 18 | 19 | close = () => { 20 | console.log("Payment closed"); 21 | } 22 | 23 | getReference = () => { 24 | let text = ""; 25 | let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.="; 26 | 27 | for( let i=0; i < 15; i++ ) 28 | text += possible.charAt(Math.floor(Math.random() * possible.length)); 29 | 30 | return text; 31 | } 32 | 33 | render() { 34 | return ( 35 |
36 |

37 | Make Payment 40 | callback={this.callback} 41 | close={this.close} 42 | disabled={false} 43 | embed={false} 44 | reference={this.getReference()} 45 | email={this.state.email} 46 | amount={this.state.amount} 47 | paystackkey={this.state.key} 48 | tag="button" 49 | /> 50 |

51 |
52 | secured-by-paystack 53 |
54 |
55 | ); 56 | } 57 | } 58 | 59 | export default App; 60 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import App from './App' 4 | 5 | it('renders without crashing', () => { 6 | const div = document.createElement('div') 7 | ReactDOM.render(, div) 8 | ReactDOM.unmountComponentAtNode(div) 9 | }) 10 | -------------------------------------------------------------------------------- /src/img/secured-by-paystack.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Developerayo/paystack-payment/b6d4b183924f893beab4033e666f064c20996ba3/src/img/secured-by-paystack.png -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", 4 | "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import './index.css' 4 | import App from './App' 5 | import * as serviceWorker from './serviceWorker' 6 | 7 | ReactDOM.render(, document.getElementById('root')) 8 | 9 | // If you want your app to work offline and load faster, you can change 10 | // unregister() to register() below. Note this comes with some pitfalls. 11 | // Learn more about service workers: https://bit.ly/CRA-PWA 12 | serviceWorker.unregister() 13 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/serviceWorker.js: -------------------------------------------------------------------------------- 1 | const isLocalhost = Boolean( 2 | window.location.hostname === 'localhost' || 3 | // [::1] is the IPv6 localhost address. 4 | window.location.hostname === '[::1]' || 5 | // 127.0.0.1/8 is considered localhost for IPv4. 6 | window.location.hostname.match( 7 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 8 | ) 9 | ) 10 | 11 | export function register (config) { 12 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 13 | // The URL constructor is available in all browsers that support SW. 14 | const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href) 15 | if (publicUrl.origin !== window.location.origin) { 16 | // Our service worker won't work if PUBLIC_URL is on a different origin 17 | // from what our page is served on. This might happen if a CDN is used to 18 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 19 | return 20 | } 21 | 22 | window.addEventListener('load', () => { 23 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js` 24 | 25 | if (isLocalhost) { 26 | // This is running on localhost. Let's check if a service worker still exists or not. 27 | checkValidServiceWorker(swUrl, config) 28 | 29 | // Add some additional logging to localhost, pointing developers to the 30 | // service worker/PWA documentation. 31 | navigator.serviceWorker.ready.then(() => { 32 | console.log( 33 | 'This web app is being served cache-first by a service ' + 34 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 35 | ) 36 | }) 37 | } else { 38 | // Is not localhost. Just register service worker 39 | registerValidSW(swUrl, config) 40 | } 41 | }) 42 | } 43 | } 44 | 45 | function registerValidSW (swUrl, config) { 46 | navigator.serviceWorker 47 | .register(swUrl) 48 | .then(registration => { 49 | registration.onupdatefound = () => { 50 | const installingWorker = registration.installing 51 | if (installingWorker == null) { 52 | return 53 | } 54 | installingWorker.onstatechange = () => { 55 | if (installingWorker.state === 'installed') { 56 | if (navigator.serviceWorker.controller) { 57 | // At this point, the updated precached content has been fetched, 58 | // but the previous service worker will still serve the older 59 | // content until all client tabs are closed. 60 | console.log( 61 | 'New content is available and will be used when all ' + 62 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 63 | ) 64 | 65 | // Execute callback 66 | if (config && config.onUpdate) { 67 | config.onUpdate(registration) 68 | } 69 | } else { 70 | // At this point, everything has been precached. 71 | // It's the perfect time to display a 72 | // "Content is cached for offline use." message. 73 | console.log('Content is cached for offline use.') 74 | 75 | // Execute callback 76 | if (config && config.onSuccess) { 77 | config.onSuccess(registration) 78 | } 79 | } 80 | } 81 | } 82 | } 83 | }) 84 | .catch(error => { 85 | console.error('Error during service worker registration:', error) 86 | }) 87 | } 88 | 89 | function checkValidServiceWorker (swUrl, config) { 90 | // Check if the service worker can be found. If it can't reload the page. 91 | fetch(swUrl) 92 | .then(response => { 93 | // Ensure service worker exists, and that we really are getting a JS file. 94 | const contentType = response.headers.get('content-type') 95 | if ( 96 | response.status === 404 || 97 | (contentType != null && contentType.indexOf('javascript') === -1) 98 | ) { 99 | // No service worker found. Probably a different app. Reload the page. 100 | navigator.serviceWorker.ready.then(registration => { 101 | registration.unregister().then(() => { 102 | window.location.reload() 103 | }) 104 | }) 105 | } else { 106 | // Service worker found. Proceed as normal. 107 | registerValidSW(swUrl, config) 108 | } 109 | }) 110 | .catch(() => { 111 | console.log( 112 | 'No internet connection found. App is running in offline mode.' 113 | ) 114 | }) 115 | } 116 | 117 | export function unregister () { 118 | if ('serviceWorker' in navigator) { 119 | navigator.serviceWorker.ready.then(registration => { 120 | registration.unregister() 121 | }) 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/style.css: -------------------------------------------------------------------------------- 1 | .body { 2 | margin-top: 250px; 3 | text-align: center; 4 | } 5 | .paystack_payment_button { 6 | display: inline-block; 7 | border-radius: 4px; 8 | background-color: #08A4DA; 9 | border: none; 10 | color: #FFFFFF; 11 | text-align: center; 12 | font-size: 28px; 13 | padding: 14px; 14 | width: 300px; 15 | transition: all 0.5s; 16 | cursor: pointer; 17 | margin: 5px; 18 | } 19 | 20 | .paystack_payment_button span { 21 | cursor: pointer; 22 | display: inline-block; 23 | position: relative; 24 | transition: 0.5s; 25 | } 26 | 27 | .paystack_payment_button span:after { 28 | content: '\00bb'; 29 | position: absolute; 30 | opacity: 0; 31 | top: 0; 32 | right: -20px; 33 | transition: 0.5s; 34 | } 35 | 36 | .paystack_payment_button:hover { 37 | box-shadow: 0 0px 0px 0 rgba(0,0,0,0.24), 0 1px 10px 0 rgba(0,0,0,0.19); 38 | } 39 | 40 | .paystack_payment_button:hover span { 41 | padding-right: 25px; 42 | } 43 | 44 | .paystack_payment_button:hover span:after { 45 | opacity: 1; 46 | right: 0; 47 | } 48 | 49 | #register, #login { 50 | width: 300px; 51 | border: 1px solid #d6d7da; 52 | padding: 0px 15px 15px 15px; 53 | border-radius: 5px; 54 | font-family: arial; 55 | line-height: 16px; 56 | color: #333333; 57 | font-size: 14px; 58 | background: #ffffff; 59 | margin: 100px auto; 60 | } 61 | 62 | form label, form input { 63 | display: block; 64 | //margin-bottom: 10px; 65 | width: 90% 66 | } 67 | 68 | form input { 69 | padding: 10px; 70 | border: solid 1px #BDC7D8; 71 | 72 | } 73 | 74 | .button { 75 | background-color: #00BFFF; 76 | border-color: #3ac162; 77 | font-weight: bold; 78 | padding: 12px 15px; 79 | color: #ffffff; 80 | } 81 | 82 | .errorMsg { 83 | color: #cc0000; 84 | margin-bottom: 12px; 85 | } 86 | 87 | .sucessMsg { 88 | color: #6B8E23; 89 | margin-bottom: 10px; 90 | } 91 | 92 | .secure { 93 | 94 | padding-top: 55px; 95 | text-align: center; 96 | display: block; 97 | justify-content: center; 98 | align-items: center; 99 | margin: auto; 100 | max-width: 380px !important; 101 | 102 | } --------------------------------------------------------------------------------