Skip to content

Commit 588edf1

Browse files
author
Felix Cheruiyot
committed
Use intasend-sdk version 3.0.3
1 parent a202a81 commit 588edf1

File tree

3 files changed

+53
-762
lines changed

3 files changed

+53
-762
lines changed

package.json

+2-19
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,11 @@
22
"name": "intasend-react-example",
33
"version": "0.1.0",
44
"private": true,
5-
"babel": {
6-
"presets": [
7-
"@babel/preset-env",
8-
"@babel/preset-react"
9-
],
10-
"plugins": [
11-
[
12-
"@babel/plugin-proposal-class-properties",
13-
{
14-
"loose": true
15-
}
16-
]
17-
]
18-
},
195
"dependencies": {
206
"@testing-library/jest-dom": "^5.11.4",
217
"@testing-library/react": "^11.1.0",
228
"@testing-library/user-event": "^12.1.10",
23-
"intasend-inlinejs-sdk": "2.0.8",
9+
"intasend-inlinejs-sdk": "^3.0.3",
2410
"react": "^17.0.2",
2511
"react-dom": "^17.0.2",
2612
"react-scripts": "4.0.3",
@@ -50,8 +36,5 @@
5036
"last 1 safari version"
5137
]
5238
},
53-
"devDependencies": {
54-
"@babel/plugin-proposal-class-properties": "^7.14.5",
55-
"babel-plugin-transform-class-properties": "^6.24.1"
56-
}
39+
"devDependencies": {}
5740
}

src/App.js

+5-36
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,21 @@
1-
// import logo from './logo.svg';
21
import './App.css';
32
import IntaSend from "intasend-inlinejs-sdk";
4-
import { useCallback, useEffect } from 'react';
53

64
function App() {
5+
// Replace with your public key
76
const PUBLIC_KEY = "ISPubKey_test_91ffc81a-8ac4-419e-8008-7091caa8d73f";
87

9-
let instance = IntaSend.setup({
8+
let instance = new IntaSend({
109
publicAPIKey: PUBLIC_KEY,
1110
live: false // Set to true when going live
1211
});
1312

1413
const handleClick = () => {
1514
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)})
1718
}
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-
5019
return (
5120

5221
<div className="App">

0 commit comments

Comments
 (0)