|
1 |
| -// import logo from './logo.svg'; |
2 | 1 | import './App.css';
|
3 | 2 | import IntaSend from "intasend-inlinejs-sdk";
|
4 |
| -import { useCallback, useEffect } from 'react'; |
5 | 3 |
|
6 | 4 | function App() {
|
| 5 | + // Replace with your public key |
7 | 6 | const PUBLIC_KEY = "ISPubKey_test_91ffc81a-8ac4-419e-8008-7091caa8d73f";
|
8 | 7 |
|
9 |
| - let instance = IntaSend.setup({ |
| 8 | + let instance = new IntaSend({ |
10 | 9 | publicAPIKey: PUBLIC_KEY,
|
11 | 10 | live: false // Set to true when going live
|
12 | 11 | });
|
13 | 12 |
|
14 | 13 | const handleClick = () => {
|
15 | 14 | instance
|
16 |
| - .run({ amount: 10, currency: "KES", api_ref: "<ORDER-NUMBER-OR-USER-ID>" }) |
| 15 | + .run({ amount: 10, currency: "KES", api_ref: "ORDER-NUMBER-OR-USER-ID" }) |
| 16 | + .on("COMPLETE", (response)=>{console.log("COMPLETE:", response)}) |
| 17 | + .on("FAILED", (response)=>{console.log("FAILED:", response)}) |
17 | 18 | }
|
18 |
| - |
19 |
| - // Listen for events |
20 |
| - const bindEvent =useCallback((element, eventName, eventHandler) => { |
21 |
| - if (element.addEventListener) { |
22 |
| - element.addEventListener(eventName, eventHandler, false); |
23 |
| - } else if (element.attachEvent) { |
24 |
| - element.attachEvent('on' + eventName, eventHandler); |
25 |
| - } |
26 |
| - }, []); |
27 |
| - |
28 |
| - const handleMessageEvent = useCallback((e) =>{ |
29 |
| - const res = e.data.message |
30 |
| - if (res) { |
31 |
| - if (res.identitier === 'intasend-status-update-cdrtl') { |
32 |
| - if (res.state === "COMPLETE") { |
33 |
| - // Do something on pay success |
34 |
| - alert("Complete:"+JSON.stringify(res)) |
35 |
| - } |
36 |
| - } |
37 |
| - } |
38 |
| - }, []); |
39 |
| - useEffect(() => { |
40 |
| - bindEvent(window, 'message', handleMessageEvent); |
41 |
| - return () => { |
42 |
| - if (window.addEventListener) { |
43 |
| - window.removeEventListener('message', handleMessageEvent); |
44 |
| - } else if (window.attachEvent) { |
45 |
| - window.detachEvent('onmessage', handleMessageEvent); |
46 |
| - } |
47 |
| - } |
48 |
| - }, [bindEvent, handleMessageEvent]); |
49 |
| - |
50 | 19 | return (
|
51 | 20 |
|
52 | 21 | <div className="App">
|
|
0 commit comments