ouisys-engine 2.1.21 → 2.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/click2sms.js +357 -0
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.js +88 -164
- package/dist/api/mo.js +274 -0
- package/dist/api/moRedir.js +186 -0
- package/dist/api/oneClick.js +366 -0
- package/dist/api/pin.js +493 -0
- package/dist/api/strategies.js +704 -0
- package/dist/api/ussd.js +1 -0
- package/dist/app/store.js +35 -0
- package/dist/common-types/AppThunk.d.ts +1 -2
- package/dist/features/strategies/categories/askMobileNumber.js +395 -0
- package/dist/features/strategies/categories/askOperator.js +311 -0
- package/dist/features/strategies/categories/detectOperatorByIp.js +606 -0
- package/dist/features/strategies/categories/headerEnrichment.js +670 -0
- package/dist/features/strategies/categories/typings/click2smsSliceTypes.js +12 -0
- package/dist/features/strategies/categories/typings/identifySliceTypes.js +22 -0
- package/dist/features/strategies/categories/typings/moFlowSliceTypes.js +22 -0
- package/dist/features/strategies/categories/typings/moRedirFlowSliceTypes.js +21 -0
- package/dist/features/strategies/categories/typings/oneClickSliceTypes.js +13 -0
- package/dist/features/strategies/categories/typings/pinFlowSliceTypes.js +13 -0
- package/dist/features/strategies/click2smsFlowSlice.js +172 -0
- package/dist/features/strategies/identifySlice.js +455 -0
- package/dist/features/strategies/moFlowSlice.js +196 -0
- package/dist/features/strategies/moRedirFlowSlice.js +190 -0
- package/dist/features/strategies/oneClickFlowSlice.js +277 -0
- package/dist/features/strategies/pinFlowSlice.js +313 -0
- package/dist/features/strategies/ussdFlowSlice.js +1 -0
- package/dist/flows/strategy.d.ts +1 -2
- package/dist/flows/strategy.js +1 -5
- package/dist/ips/tryGetIPRangeName.js +14 -13
- package/dist/mockServer/browser.js +48 -0
- package/dist/mockServer/handlers.js +22 -0
- package/dist/mockServer/server.js +48 -0
- package/dist/pacman/index.js +0 -1
- package/dist/reducers/click2smsFlow/utils.js +1 -3
- package/dist/reducers/moRedirFlow/utils.js +1 -1
- package/dist/reducers/oneClickFlow/utils.js +47 -19
- package/dist/reducers/pinFlow/utils.js +7 -12
- package/dist/reducers/strategy/utils.js +12 -13
- package/dist/reducers/tpayHeFlow/utils.js +1 -1
- package/dist/store/index.d.ts +1 -2
- package/dist/store/reducers.d.ts +0 -2
- package/dist/store/reducers.js +1 -4
- package/dist/test/setup.js +24 -0
- package/dist/test/test-utils.js +51 -0
- package/dist/utilities/loadScriptInnerHtml.d.ts +2 -0
- package/dist/utilities/loadScriptInnerHtml.js +18 -0
- package/package.json +1 -1
- package/src/api/index.ts +4 -37
- package/src/common-types/AppThunk.ts +1 -2
- package/src/flows/strategy.ts +1 -5
- package/src/ips/tryGetIPRangeName.ts +3 -2
- package/src/pacman/index.ts +1 -1
- package/src/reducers/click2smsFlow/utils.ts +0 -3
- package/src/reducers/moRedirFlow/utils.ts +1 -1
- package/src/reducers/oneClickFlow/utils.ts +77 -11
- package/src/reducers/pinFlow/utils.ts +2 -9
- package/src/reducers/strategy/utils.ts +2 -3
- package/src/store/index.ts +1 -2
- package/src/store/reducers.ts +1 -5
- package/src/utilities/loadScriptInnerHtml.ts +10 -0
- package/yarn.lock +5204 -0
- package/src/flows/tpayHeFlow.ts +0 -20
- package/src/reducers/tpayHeFlow/ITpayHeConstants.ts +0 -7
- package/src/reducers/tpayHeFlow/TpayHeTypes.ts +0 -135
- package/src/reducers/tpayHeFlow/index.ts +0 -207
- package/src/reducers/tpayHeFlow/utils.ts +0 -311
package/src/flows/tpayHeFlow.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import * as RDS from "../common-types/RemoteDataState";
|
|
2
|
-
|
|
3
|
-
import { CONFIRMTpayFailure, CONFIRMTpaySuccess, ILOADTPAYFailure, ILOADTPAYSuccess, ITpayHeCurrentState } from "../reducers/tpayHeFlow/TpayHeTypes";
|
|
4
|
-
|
|
5
|
-
function tpayHeFlowMatch <R>(
|
|
6
|
-
{ loadTpay, confirmTpay }:
|
|
7
|
-
{ loadTpay: (rds: RDS.RemoteDataState<ILOADTPAYFailure, ILOADTPAYSuccess>) => R,
|
|
8
|
-
confirmTpay: (rds: RDS.RemoteDataState<CONFIRMTpayFailure, CONFIRMTpaySuccess>) => R
|
|
9
|
-
}): (state: ITpayHeCurrentState) => R {
|
|
10
|
-
return state => {
|
|
11
|
-
switch (state.type) {
|
|
12
|
-
case 'LOAD_TPAY_HE':
|
|
13
|
-
return loadTpay(state.result)
|
|
14
|
-
case 'CONFIRM_TPAY':
|
|
15
|
-
return confirmTpay(state.result)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default tpayHeFlowMatch;
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
import * as RDS from "../../common-types/RemoteDataState";
|
|
2
|
-
import { AppThunk } from "../../common-types/AppThunk";
|
|
3
|
-
|
|
4
|
-
export type ILOADTPAYFailure = {
|
|
5
|
-
errorType:LOADTPAYErrorTypes;
|
|
6
|
-
productUrl?:string;
|
|
7
|
-
}
|
|
8
|
-
export type ILOADTPAYSuccess = {
|
|
9
|
-
redirectUrl:string;
|
|
10
|
-
nextAction:"getRedirectUrlAction";
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export type LOADTPAYErrorTypes = "UnknownError" | "NotSupported" | "UnexpectedState" | "InvalidConfig" | "AlreadySubscribed" | "SubscriptionFailed";
|
|
14
|
-
|
|
15
|
-
export type ITpayHeCurrentState = {
|
|
16
|
-
type: "LOAD_TPAY_HE",
|
|
17
|
-
result:RDS.RemoteDataState<ILOADTPAYFailure, ILOADTPAYSuccess>
|
|
18
|
-
}
|
|
19
|
-
|
|
|
20
|
-
{
|
|
21
|
-
type: "CONFIRM_TPAY";
|
|
22
|
-
result:RDS.RemoteDataState<CONFIRMTpayFailure, CONFIRMTpaySuccess>
|
|
23
|
-
}
|
|
24
|
-
export type ITpayHeFlowReducerState =
|
|
25
|
-
{
|
|
26
|
-
currentState:ITpayHeCurrentState;
|
|
27
|
-
tpayConfig:ITpayConsentResult;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type ILoadTpayPayload = {
|
|
31
|
-
type:"LOAD_TPAY_HE",
|
|
32
|
-
result:RDS.RemoteDataState<ILOADTPAYFailure, ILOADTPAYSuccess>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export type ITpayHeFlowActionMaps = {
|
|
36
|
-
loadTpayAction:(theme:string, locale:string)=>AppThunk
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export type IConfirmTpayPayload = {
|
|
41
|
-
type: "CONFIRM_TPAY";
|
|
42
|
-
result: RDS.RemoteDataState<CONFIRMTpayFailure, CONFIRMTpaySuccess>;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type CONFIRMTpayFailure = {
|
|
46
|
-
errorType: CONFIRMTpayErrorTypes;
|
|
47
|
-
error?: Error;
|
|
48
|
-
productUrl?:string;
|
|
49
|
-
};
|
|
50
|
-
export type CONFIRMTpaySuccess = { finalUrl: string};
|
|
51
|
-
export type CONFIRMTpayErrorTypes = "UnknownError" | "TooEarly" | "UnexpectedState" | "AlreadySubscribed" | "ConfirmError";
|
|
52
|
-
|
|
53
|
-
export type ITpayHeActions = {
|
|
54
|
-
type:"LOAD_TPAY_HE";
|
|
55
|
-
payload:ILoadTpayPayload;
|
|
56
|
-
}
|
|
57
|
-
|
|
|
58
|
-
{
|
|
59
|
-
type: "CONFIRM_TPAY_CLICK";
|
|
60
|
-
payload:IConfirmTpayPayload
|
|
61
|
-
}
|
|
62
|
-
|
|
|
63
|
-
{
|
|
64
|
-
type: "LOAD_TPAY_HE_SUCCESS";
|
|
65
|
-
payload:ILoadTpayPayload
|
|
66
|
-
}
|
|
67
|
-
|
|
|
68
|
-
{
|
|
69
|
-
type:"MOCK_TPAY_FLOW_STATE";
|
|
70
|
-
payload:ILoadTpayPayload;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export type IConfig = {
|
|
76
|
-
host?: string, country?: string, slug?: string, queryString?: Array<[string, string]>, device?:string
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export type ITpayConsentResult = {
|
|
80
|
-
prodSku: string;
|
|
81
|
-
lang: string;
|
|
82
|
-
country: string;
|
|
83
|
-
config: ITPayConfig;
|
|
84
|
-
redirectUrl: string;
|
|
85
|
-
subscription_url:string;
|
|
86
|
-
rid: string;
|
|
87
|
-
success: true;
|
|
88
|
-
} | {
|
|
89
|
-
success: false
|
|
90
|
-
rockman_id: string
|
|
91
|
-
message: string
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export interface ITPayConfig {
|
|
95
|
-
product_url: string;
|
|
96
|
-
subscription_plan_id: number;
|
|
97
|
-
public: string;
|
|
98
|
-
private: string;
|
|
99
|
-
flow: string;
|
|
100
|
-
catalog_name: { [key: string]: string };
|
|
101
|
-
replace_uid?:boolean;
|
|
102
|
-
product_full_access?:string;
|
|
103
|
-
domain?:string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export type IRedirectResult = {
|
|
108
|
-
Status:string;
|
|
109
|
-
OperatorCode:number;
|
|
110
|
-
SessionId:number;
|
|
111
|
-
OrderId:number;
|
|
112
|
-
Details:string;
|
|
113
|
-
SubId:string;
|
|
114
|
-
Signature:string;
|
|
115
|
-
SessionToken:string;
|
|
116
|
-
rockman_id:string;
|
|
117
|
-
ReferenceCode:string;
|
|
118
|
-
Msisdn:string;
|
|
119
|
-
subscription_url:string;
|
|
120
|
-
language_code:string;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
export type IMockTpayFlowStates = "confirm-state"
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
export type ITpaySubscribeResult = {
|
|
127
|
-
success:true;
|
|
128
|
-
rockman_id: string;
|
|
129
|
-
product_url:string;
|
|
130
|
-
} |
|
|
131
|
-
{
|
|
132
|
-
success: false;
|
|
133
|
-
rockman_id: string;
|
|
134
|
-
message: string;
|
|
135
|
-
}
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
// LIBRARIES
|
|
2
|
-
import * as RDS from "../../common-types/RemoteDataState";
|
|
3
|
-
|
|
4
|
-
import { ITpayHeFlowReducerState, ITpayHeActions, ITpayHeFlowActionMaps, ILOADTPAYFailure, ILOADTPAYSuccess, ILoadTpayPayload, CONFIRMTpayErrorTypes, CONFIRMTpayFailure, CONFIRMTpaySuccess, ITPayConfig, ITpayConsentResult, LOADTPAYErrorTypes, IMockTpayFlowStates } from "./TpayHeTypes";
|
|
5
|
-
import { AppThunk } from "../../common-types/AppThunk";
|
|
6
|
-
import { confirmTPay, confirmTPayCheck, getTpayConfig, mockedConfirmState } from "./utils";
|
|
7
|
-
import { genericHandler, tracker } from "../strategy";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
//ACTION CREATORS
|
|
13
|
-
export function loadTpayAction(theme:string, locale:string):AppThunk{
|
|
14
|
-
return async (dispatch, store)=>{
|
|
15
|
-
const {currentState} = store().strategy
|
|
16
|
-
if(currentState.type === "TPAY_HE"){
|
|
17
|
-
const config = currentState.result.config;
|
|
18
|
-
try {
|
|
19
|
-
|
|
20
|
-
//Check if Error or Success Page
|
|
21
|
-
const product_url = await confirmTPayCheck();
|
|
22
|
-
if(product_url !== null){
|
|
23
|
-
window.location.href = product_url;
|
|
24
|
-
}else{
|
|
25
|
-
dispatch({
|
|
26
|
-
type: "LOAD_TPAY_HE",
|
|
27
|
-
payload:{
|
|
28
|
-
type: "LOAD_TPAY_HE",
|
|
29
|
-
result: RDS.Loading()
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
const result = await getTpayConfig(
|
|
34
|
-
window,
|
|
35
|
-
config
|
|
36
|
-
)
|
|
37
|
-
// await addLookUpTpay(result, theme, locale);
|
|
38
|
-
|
|
39
|
-
tracker.advancedInFlow('tallyman.v1-tpay-he', 'load-tpay-success');
|
|
40
|
-
|
|
41
|
-
dispatch({
|
|
42
|
-
type: "LOAD_TPAY_HE_SUCCESS",
|
|
43
|
-
payload:{
|
|
44
|
-
type: "LOAD_TPAY_HE",
|
|
45
|
-
result: RDS.Success(result)
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
} catch (ex) {
|
|
51
|
-
console.warn(ex);
|
|
52
|
-
//@ts-ignore
|
|
53
|
-
const errorType: LOADTPAYErrorTypes =
|
|
54
|
-
"AlreadySubscribed" === ex.type
|
|
55
|
-
? "AlreadySubscribed"
|
|
56
|
-
: "NotSupported" === ex.type
|
|
57
|
-
? "NotSupported"
|
|
58
|
-
: "SubscriptionFailed" === ex.type
|
|
59
|
-
? "SubscriptionFailed"
|
|
60
|
-
: "UnknownError";
|
|
61
|
-
|
|
62
|
-
tracker.recedeInFlow('tallyman.v1-tpay-he', 'tpay-config-failure',{errorType: errorType || 'UnknownError'})
|
|
63
|
-
dispatch({
|
|
64
|
-
type: "LOAD_TPAY_HE",
|
|
65
|
-
payload:{
|
|
66
|
-
type: "LOAD_TPAY_HE",
|
|
67
|
-
result: RDS.Failure({
|
|
68
|
-
errorType: errorType,
|
|
69
|
-
error: ex
|
|
70
|
-
})
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
dispatch({
|
|
75
|
-
type:"IDENTIFY_STRATEGY",
|
|
76
|
-
payload:{
|
|
77
|
-
type:"PIN",
|
|
78
|
-
result: {
|
|
79
|
-
nextAction:"submitMSISDNAction",
|
|
80
|
-
config:config
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
}else{
|
|
86
|
-
tracker.recedeInFlow('tallyman.v1-tpay-he', 'tpay-config-failure',{errorType: 'UnknownError'})
|
|
87
|
-
dispatch({
|
|
88
|
-
type: "LOAD_TPAY_HE",
|
|
89
|
-
payload:{
|
|
90
|
-
type: "LOAD_TPAY_HE",
|
|
91
|
-
result: RDS.Failure({
|
|
92
|
-
errorType:"UnexpectedState"
|
|
93
|
-
})
|
|
94
|
-
}
|
|
95
|
-
})
|
|
96
|
-
throw "Unexpected state";
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
export function confirmTpayAction(locale:string, redirectUrl?:string):AppThunk{
|
|
104
|
-
return async (dispatch, store)=>{
|
|
105
|
-
try {
|
|
106
|
-
dispatch({
|
|
107
|
-
type: "CONFIRM_TPAY_CLICK",
|
|
108
|
-
payload:{
|
|
109
|
-
type: "CONFIRM_TPAY",
|
|
110
|
-
result: RDS.Loading()
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
tracker.advancedInFlow('tallyman.v1-tpay-he', 'confirm-tpay-clicked',{})
|
|
114
|
-
const {currentState} = store().strategy
|
|
115
|
-
if(currentState.type === "TPAY_HE"){
|
|
116
|
-
const {tpayConfig} = store().tpayHeFlow
|
|
117
|
-
//@ts-ignore
|
|
118
|
-
const result = await confirmTPay(window, tpayConfig, locale, redirectUrl)
|
|
119
|
-
tracker.advancedInFlow('tallyman.v1-tpay-he', 'confirm-tpay-success',{finalUrl: result})
|
|
120
|
-
|
|
121
|
-
dispatch({
|
|
122
|
-
type: "CONFIRM_TPAY_CLICK",
|
|
123
|
-
payload:{
|
|
124
|
-
type:"CONFIRM_TPAY",
|
|
125
|
-
result: RDS.Success<CONFIRMTpayFailure, CONFIRMTpaySuccess>({
|
|
126
|
-
finalUrl: ""
|
|
127
|
-
})
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
}else{
|
|
131
|
-
tracker.recedeInFlow('tallyman.v1-tpay-he', 'confirm-tpay-failure',{})
|
|
132
|
-
dispatch({
|
|
133
|
-
type: "CONFIRM_TPAY_CLICK",
|
|
134
|
-
payload:{
|
|
135
|
-
type:"CONFIRM_TPAY",
|
|
136
|
-
result: RDS.Failure<CONFIRMTpayFailure, CONFIRMTpaySuccess>({errorType: "UnexpectedState"})
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
throw "Unexpected state"
|
|
140
|
-
}
|
|
141
|
-
} catch(ex) {
|
|
142
|
-
console.error(ex)
|
|
143
|
-
const errorType: CONFIRMTpayErrorTypes =
|
|
144
|
-
"AlreadySubscribed" === ex.type
|
|
145
|
-
? "AlreadySubscribed"
|
|
146
|
-
: "ConfirmError" === ex.type
|
|
147
|
-
? "ConfirmError"
|
|
148
|
-
: "UnknownError";
|
|
149
|
-
tracker.recedeInFlow('tallyman.v1-tpay-he', 'confirm-tpay',{errorType: errorType || 'UnknownError'})
|
|
150
|
-
|
|
151
|
-
dispatch({
|
|
152
|
-
type: "CONFIRM_TPAY_CLICK",
|
|
153
|
-
payload:{
|
|
154
|
-
type:"CONFIRM_TPAY",
|
|
155
|
-
result: RDS.Failure<CONFIRMTpayFailure, CONFIRMTpaySuccess>({errorType: errorType || 'UnknownError'})
|
|
156
|
-
}
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
export function mockTpayFlow(mockState:IMockTpayFlowStates):AppThunk {
|
|
166
|
-
return (dispatch)=>{
|
|
167
|
-
if(mockState !== undefined){
|
|
168
|
-
switch (mockState) {
|
|
169
|
-
case "confirm-state":
|
|
170
|
-
return dispatch({
|
|
171
|
-
type:"MOCK_TPAY_FLOW_STATE",
|
|
172
|
-
payload:mockedConfirmState.currentState
|
|
173
|
-
})
|
|
174
|
-
default:
|
|
175
|
-
throw "Mock Flow not supported";
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const initialState:ITpayHeFlowReducerState = {
|
|
183
|
-
currentState:{
|
|
184
|
-
type: "LOAD_TPAY_HE",
|
|
185
|
-
result: RDS.NothingYet<ILOADTPAYFailure, ILOADTPAYSuccess>()
|
|
186
|
-
},
|
|
187
|
-
tpayConfig:null
|
|
188
|
-
};
|
|
189
|
-
export const TpayHeFlowFlowActionMaps:ITpayHeFlowActionMaps = {
|
|
190
|
-
loadTpayAction:loadTpayAction
|
|
191
|
-
}
|
|
192
|
-
export default function TpayHeFlowReducer(state = initialState, action:ITpayHeActions) {
|
|
193
|
-
switch (action.type) {
|
|
194
|
-
case "LOAD_TPAY_HE":
|
|
195
|
-
return genericHandler<ITpayHeFlowReducerState, ILoadTpayPayload>(state, action.payload)
|
|
196
|
-
case "CONFIRM_TPAY_CLICK":
|
|
197
|
-
//@ts-ignore
|
|
198
|
-
return genericHandler<ITpayHeFlowReducerState, ILoadTpayPayload>(state, action.payload)
|
|
199
|
-
case "LOAD_TPAY_HE_SUCCESS":
|
|
200
|
-
return genericHandler<ITpayHeFlowReducerState, ILoadTpayPayload>(state, action.payload)
|
|
201
|
-
case "MOCK_TPAY_FLOW_STATE":
|
|
202
|
-
//@ts-ignore
|
|
203
|
-
return handleMockFlow<ITpayHeFlowReducerState, any>(state, action.payload)
|
|
204
|
-
default:
|
|
205
|
-
return state;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
@@ -1,311 +0,0 @@
|
|
|
1
|
-
import { IConfig, ILOADTPAYFailure, ILOADTPAYSuccess, IRedirectResult, ITpayHeFlowReducerState, ITpaySubscribeResult } from "./TpayHeTypes";
|
|
2
|
-
|
|
3
|
-
import * as RDS from "../../common-types/RemoteDataState";
|
|
4
|
-
import IError from "../../common-types/IError";
|
|
5
|
-
import { ITpayConsentResult } from "./TpayHeTypes";
|
|
6
|
-
import { searchToObject } from "../strategy/utils";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export const additionalQueryString = `msisdnSubmitted=Y&legalCheckbox=Y&incentivizedCheckbox=Y&op_confirmCheckbox=N`
|
|
10
|
-
|
|
11
|
-
export default class ScriptLoader {
|
|
12
|
-
private src: string;
|
|
13
|
-
private global: string;
|
|
14
|
-
private protocol: string;
|
|
15
|
-
private isLoaded: boolean;
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
constructor (options:{src:string, global:string, protocol?:string}) {
|
|
19
|
-
const { src, global, protocol = document.location.protocol } = options
|
|
20
|
-
this.src = src
|
|
21
|
-
this.global = global
|
|
22
|
-
this.protocol = protocol
|
|
23
|
-
this.isLoaded = false
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
loadScript () {
|
|
27
|
-
return new Promise((resolve, reject) => {
|
|
28
|
-
// Create script element and set attributes
|
|
29
|
-
const script = document.createElement('script')
|
|
30
|
-
script.type = 'text/javascript'
|
|
31
|
-
script.async = true
|
|
32
|
-
script.src = `${this.protocol}//${this.src}`
|
|
33
|
-
|
|
34
|
-
// Append the script to the DOM
|
|
35
|
-
const el = document.getElementsByTagName('script')[0]
|
|
36
|
-
el.parentNode.insertBefore(script, el)
|
|
37
|
-
|
|
38
|
-
// Resolve the promise once the script is loaded
|
|
39
|
-
script.addEventListener('load', () => {
|
|
40
|
-
this.isLoaded = true
|
|
41
|
-
resolve(script)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
// Catch any errors while loading the script
|
|
45
|
-
script.addEventListener('error', () => {
|
|
46
|
-
reject(new Error(`${this.src} failed to load.`))
|
|
47
|
-
})
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
load () {
|
|
52
|
-
return new Promise(async (resolve, reject) => {
|
|
53
|
-
if (!this.isLoaded) {
|
|
54
|
-
try {
|
|
55
|
-
await this.loadScript()
|
|
56
|
-
//@ts-ignore
|
|
57
|
-
resolve(window[this.global])
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e)
|
|
60
|
-
}
|
|
61
|
-
} else {
|
|
62
|
-
//@ts-ignore
|
|
63
|
-
resolve(window[this.global])
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export const getTpayConfig = async(window:Window, maybeConfig: IConfig): Promise<ITpayConsentResult> => {
|
|
70
|
-
if (typeof window == "undefined") {
|
|
71
|
-
throw "javascript: console.error('SSR'); void 6"
|
|
72
|
-
} else {
|
|
73
|
-
const { host, country, slug, queryString, device} = maybeConfig
|
|
74
|
-
const offer = window.pac_analytics.visitor.offer
|
|
75
|
-
const s = window.location.search.substr(1)
|
|
76
|
-
const search = (!!s && s.length > 0 ? [s] : []).concat((queryString || []).map(([k, v]) => `${k}=${v}`)).join('&')
|
|
77
|
-
const rockmanId = window.pac_analytics.visitor.rockmanId
|
|
78
|
-
const result: ITpayConsentResult = await window.tallymanApi.tpayConsentConfig(host, country, slug, device, offer, rockmanId, search)
|
|
79
|
-
if (false == result.success) {
|
|
80
|
-
const error = new Error(`Error in getTpayConfig() tpay-consent-config action:\n${result.message}`) as IError & {type:string; productUrl:string;}
|
|
81
|
-
error['type'] = result.message == 'ALREADY SUBSCRIBED' ? "AlreadySubscribed" : "NotSupported";
|
|
82
|
-
console.error(error)
|
|
83
|
-
throw error
|
|
84
|
-
} else {
|
|
85
|
-
return result;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// export const addLookUpTpay = async(tpayConfig:ITpayConsentResult, theme?:string, locale?:string):Promise<boolean>=>{
|
|
91
|
-
// if(tpayConfig.success != false){
|
|
92
|
-
// const { config } = tpayConfig;
|
|
93
|
-
// const s = document.createElement("script");
|
|
94
|
-
// const currentDate = moment().utc().format()
|
|
95
|
-
// const digest = ()=>{
|
|
96
|
-
// const d = currentDate + locale + theme;
|
|
97
|
-
// const hash = HmacSHA256(d, config.private);
|
|
98
|
-
// window.tPayhash = hash.toString();
|
|
99
|
-
// const base64 = config.public + ":" + hash.toString();
|
|
100
|
-
// return base64
|
|
101
|
-
// }
|
|
102
|
-
|
|
103
|
-
// try{
|
|
104
|
-
// const loader = new ScriptLoader({
|
|
105
|
-
// src: `lookup.tpay.me/idxml.ashx/js?date=${currentDate}&lang=${locale}&theme=${theme}&digest=${digest()}`,
|
|
106
|
-
// global: 'TPay'
|
|
107
|
-
// });
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// await loader.load();
|
|
111
|
-
// const operatorCode = window.TPay.HeaderEnrichment.operatorCode();
|
|
112
|
-
// console.log("operatorCode", operatorCode)
|
|
113
|
-
// if(operatorCode != ""){
|
|
114
|
-
// return true;
|
|
115
|
-
// }else{
|
|
116
|
-
// const error = new Error(`Error in addLookUpTpay() :\n MSISDN Not Detected!`) as IError & {type:string;}
|
|
117
|
-
// error['type'] = "3GConnectionError";
|
|
118
|
-
// console.error(error)
|
|
119
|
-
// throw error
|
|
120
|
-
// }
|
|
121
|
-
// }catch(err){
|
|
122
|
-
// const error = new Error(`Error in addLookUpTpay() :\n Failed To Load Script ${JSON.stringify(err)}`) as IError & {type:string;}
|
|
123
|
-
// error['type'] = "InvalidConfig";
|
|
124
|
-
// console.error(error)
|
|
125
|
-
// throw error
|
|
126
|
-
// }
|
|
127
|
-
// }else{
|
|
128
|
-
// return false;
|
|
129
|
-
// }
|
|
130
|
-
// }
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
const subscribe:(url:string)=>Promise<string> = async(url:string)=>{
|
|
135
|
-
|
|
136
|
-
const result:ITpaySubscribeResult = await fetch(url).then((x)=>x.json())
|
|
137
|
-
|
|
138
|
-
if(false === result.success){
|
|
139
|
-
const subscribeError = new Error(`Error in subscribe() one-click-subscribe action:\n${result.message}`) as IError;
|
|
140
|
-
subscribeError['type'] = "SubscriptionError";
|
|
141
|
-
throw subscribeError
|
|
142
|
-
}else{
|
|
143
|
-
return result.product_url
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export const confirmTPayCheck = async():Promise<string | null>=>{
|
|
148
|
-
const search = searchToObject() as IRedirectResult;
|
|
149
|
-
try{
|
|
150
|
-
if(search){
|
|
151
|
-
if(search["Status"] == "Error"){
|
|
152
|
-
throw search["Details"]
|
|
153
|
-
}
|
|
154
|
-
if(search["Status"] == "Success"){
|
|
155
|
-
const { Msisdn, SessionToken, ReferenceCode, Status, Details, subscription_url } = search;
|
|
156
|
-
const url = `${decodeURIComponent(subscription_url)}&msisdn=${Msisdn}&tpaySessionToken=${SessionToken}&heReferenceCode=${ReferenceCode}&heStatus=${Status}&heErrorDetails=${Details}`;
|
|
157
|
-
const product_url = await subscribe(url);
|
|
158
|
-
return product_url.replace('<%LANG%>', search.language_code);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return null;
|
|
162
|
-
}catch(err){
|
|
163
|
-
const error = new Error(`Error in confirmTPayCheck() :\n ${JSON.stringify(search)}`) as IError & {type:string;}
|
|
164
|
-
error['type'] = "SubscriptionFailed";
|
|
165
|
-
console.error(error)
|
|
166
|
-
throw error
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
export const confirmTPay = (window:Window, tpayConfig:ITpayConsentResult, locale:string, redirectUrl?:string)=>{
|
|
172
|
-
//@ts-ignore
|
|
173
|
-
if(typeof window.browser == "undefined"){
|
|
174
|
-
//@ts-ignore
|
|
175
|
-
window.browser = window.chrome
|
|
176
|
-
}
|
|
177
|
-
if(tpayConfig == null || tpayConfig.success != true){
|
|
178
|
-
const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment`) as IError & {type:string;}
|
|
179
|
-
error['type'] = "InvalidConfig";
|
|
180
|
-
console.error(error)
|
|
181
|
-
throw error
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const { config , prodSku } = tpayConfig;
|
|
185
|
-
const operatorCode = window.TPay.HeaderEnrichment.operatorCode();
|
|
186
|
-
const sessionId = window.TPay.HeaderEnrichment.sessionId();
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const catName = config["catalog_name"][operatorCode];
|
|
190
|
-
|
|
191
|
-
const subscriptionPlanId = config["subscription_plan_id"];
|
|
192
|
-
const lang = locale;
|
|
193
|
-
const rockmanId = window.pac_analytics.visitor.rockmanId
|
|
194
|
-
let operatorFQN = 'EG_ORANGE';
|
|
195
|
-
if (operatorCode == 60202) {
|
|
196
|
-
operatorFQN = 'EG_VODAFONE';
|
|
197
|
-
} else if (operatorCode == 60303) {
|
|
198
|
-
operatorFQN = 'DZ_OOREDOO';
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
console.log("operatorFQN", operatorFQN);
|
|
202
|
-
|
|
203
|
-
const availableRdrl = redirectUrl ? redirectUrl : window.location.origin + window.location.pathname;
|
|
204
|
-
|
|
205
|
-
const rUrl = `${availableRdrl}?subscription_url=${encodeURIComponent(`${tpayConfig.subscription_url}operator=${operatorFQN}&language_code=${locale}`)}&rockman_id=${rockmanId}&language_code=${locale}&`
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
console.log("Redirect url", rUrl)
|
|
209
|
-
|
|
210
|
-
const hash = window.tPayhash;
|
|
211
|
-
|
|
212
|
-
console.log("Operator Code: " + operatorCode);
|
|
213
|
-
console.log("Session Id: " + sessionId);
|
|
214
|
-
console.log("Product Catalog: " + catName);
|
|
215
|
-
console.log("Subscription Plan :" + subscriptionPlanId);
|
|
216
|
-
|
|
217
|
-
window.TPay.HeaderEnrichment.hasSubscription(prodSku, function(hasSub, subId){
|
|
218
|
-
if (hasSub) {
|
|
219
|
-
console.log("hasSubscription")
|
|
220
|
-
// User has already a subscription, go to returnSubscription
|
|
221
|
-
console.log('User is already subscribed');
|
|
222
|
-
let productUrl = config['product_url'];
|
|
223
|
-
|
|
224
|
-
if (config["replace_uid"] != undefined && config['replace_uid'] == true) {
|
|
225
|
-
console.log('sub id ' + subId);
|
|
226
|
-
productUrl = config['product_full_access'];
|
|
227
|
-
fetch(`http://de-mcb-api.sam-media.com/api/v2/validate-access/?domain=${config.domain}&sub_id=${subId}&country=${tpayConfig.country}&gateway=tpay`).then((response:any)=>{
|
|
228
|
-
if (response.payload.token) {
|
|
229
|
-
productUrl = config['product_url'].replace('<%UID%>', response.payload.token);
|
|
230
|
-
}
|
|
231
|
-
}).catch((err)=>{
|
|
232
|
-
console.warn('validate-access' + err );
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
console.log("productUrl", productUrl)
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
setTimeout(() => {
|
|
240
|
-
window.location.href = productUrl;
|
|
241
|
-
}, 1000);
|
|
242
|
-
|
|
243
|
-
console.log("productUrl", productUrl)
|
|
244
|
-
const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment.hasSubscription action:\n${'ALREADY SUBSCRIBED'}`) as IError & {type:string; productUrl:string;}
|
|
245
|
-
error['type'] = "AlreadySubscribed";
|
|
246
|
-
error['productUrl'] = productUrl;
|
|
247
|
-
console.error(error)
|
|
248
|
-
throw error
|
|
249
|
-
} else {
|
|
250
|
-
console.log("NOT ACTIVE")
|
|
251
|
-
if(config.flow != "consent"){
|
|
252
|
-
try{
|
|
253
|
-
//@ts-ignore
|
|
254
|
-
window.TPay.HeaderEnrichment.confirm(
|
|
255
|
-
subscriptionPlanId,
|
|
256
|
-
catName,
|
|
257
|
-
prodSku,
|
|
258
|
-
sessionId,
|
|
259
|
-
rUrl,
|
|
260
|
-
rockmanId,
|
|
261
|
-
lang,
|
|
262
|
-
hash
|
|
263
|
-
)
|
|
264
|
-
}catch(err){
|
|
265
|
-
const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment.confirm action:\n${JSON.stringify(err)}`) as IError & {type:string;}
|
|
266
|
-
error['type'] = "ConfirmError";
|
|
267
|
-
console.error(error)
|
|
268
|
-
}
|
|
269
|
-
}else{
|
|
270
|
-
|
|
271
|
-
// user is not active subscriber, proceed with subscription(redirect to tpay pin page)
|
|
272
|
-
try{
|
|
273
|
-
window.TPay.HeaderEnrichment.consent(
|
|
274
|
-
subscriptionPlanId,
|
|
275
|
-
catName,
|
|
276
|
-
prodSku,
|
|
277
|
-
sessionId,
|
|
278
|
-
rUrl,
|
|
279
|
-
rockmanId,
|
|
280
|
-
lang,
|
|
281
|
-
hash
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
}catch(err){
|
|
285
|
-
const error = new Error(`Error in confirmTPay() TPay.HeaderEnrichment.consent action:\n${JSON.stringify(err)}`) as IError & {type:string;}
|
|
286
|
-
error['type'] = "ConfirmError";
|
|
287
|
-
console.error(error)
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
// export const mockedSuccessState : IOneClickCurrentState = {
|
|
295
|
-
// type: "LOAD_TPAY_HE",
|
|
296
|
-
// result: RDS.Success<ILOADTPAYFailure, ILOADTPAYSuccess>({
|
|
297
|
-
// redirectUrl: 'https://www.yahoo.com/',
|
|
298
|
-
// nextAction:"getRedirectUrlAction"
|
|
299
|
-
// })
|
|
300
|
-
// }
|
|
301
|
-
|
|
302
|
-
export const mockedConfirmState : ITpayHeFlowReducerState = {
|
|
303
|
-
currentState:{
|
|
304
|
-
type: "LOAD_TPAY_HE",
|
|
305
|
-
//@ts-ignore
|
|
306
|
-
result: RDS.Success<ILOADTPAYFailure, ILOADTPAYSuccess>({}),
|
|
307
|
-
//@ts-ignore
|
|
308
|
-
tpayConfig:{}
|
|
309
|
-
|
|
310
|
-
}
|
|
311
|
-
}
|