Skip to content

Commit 21b8337

Browse files
committed
feat(example): support master account flow via MONEI-Account-ID and User-Agent
Adds optional Account ID and User-Agent inputs in the merchant demo, with the same validation rule as the Node SDK: a custom User-Agent is required when MONEI-Account-ID is set. Default UA sent on every auth-token request.
1 parent 0aae4b6 commit 21b8337

2 files changed

Lines changed: 48 additions & 4 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ curl -X POST https://api.monei.com/v1/pos/auth-token \
166166
-H "Content-Type: application/json"
167167
```
168168

169+
**Partner / master account integrations:** use your master account API key, set the sub-account ID via `MONEI-Account-ID`, and **identify yourself with a partner `User-Agent`** (`MONEI/<PARTNER_NAME>/<VERSION>`). A custom `User-Agent` is required whenever `MONEI-Account-ID` is set.
170+
171+
```bash
172+
curl -X POST https://api.monei.com/v1/pos/auth-token \
173+
-H "Authorization: pk_live_MASTER_KEY" \
174+
-H "MONEI-Account-ID: SUB_ACCOUNT_ID" \
175+
-H "User-Agent: MONEI/MyPartner/0.1.0" \
176+
-H "Content-Type: application/json"
177+
```
178+
179+
See [docs.monei.com/monei-connect](https://docs.monei.com/monei-connect) for details.
180+
169181
See the [MONEI API docs](https://docs.monei.com) for details.
170182

171183
## License

example/App.tsx

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ import * as MoneiPay from '@monei-pay/react-native';
1616

1717
type PaymentMode = 'direct' | 'via-monei-pay';
1818

19+
const DEFAULT_USER_AGENT = 'MONEI/MerchantDemoRN/0.2.1';
20+
1921
export default function App() {
2022
const [apiKey, setApiKey] = useState('');
23+
const [accountId, setAccountId] = useState('');
24+
const [userAgent, setUserAgent] = useState('');
2125
const [posId, setPosId] = useState('');
2226
const [authToken, setAuthToken] = useState('');
2327
const [amountText, setAmountText] = useState('');
@@ -39,6 +43,12 @@ export default function App() {
3943

4044
const fetchToken = async () => {
4145
setError(null);
46+
47+
if (accountId.trim() && !userAgent.trim()) {
48+
setError('User-Agent must be provided when using Account ID');
49+
return;
50+
}
51+
4252
setIsFetchingToken(true);
4353

4454
try {
@@ -47,12 +57,18 @@ export default function App() {
4757
body.pointOfSaleId = posId.trim();
4858
}
4959

60+
const headers: Record<string, string> = {
61+
Authorization: apiKey.trim(),
62+
'Content-Type': 'application/json',
63+
'User-Agent': userAgent.trim() || DEFAULT_USER_AGENT,
64+
};
65+
if (accountId.trim()) {
66+
headers['MONEI-Account-ID'] = accountId.trim();
67+
}
68+
5069
const response = await fetch('https://api.monei.com/v1/pos/auth-token', {
5170
method: 'POST',
52-
headers: {
53-
Authorization: apiKey.trim(),
54-
'Content-Type': 'application/json',
55-
},
71+
headers,
5672
body: JSON.stringify(body),
5773
});
5874

@@ -124,6 +140,22 @@ export default function App() {
124140
autoCapitalize="none"
125141
autoCorrect={false}
126142
/>
143+
<TextInput
144+
style={styles.input}
145+
placeholder="MONEI Account ID (optional, partner integrations)"
146+
value={accountId}
147+
onChangeText={setAccountId}
148+
autoCapitalize="none"
149+
autoCorrect={false}
150+
/>
151+
<TextInput
152+
style={styles.input}
153+
placeholder="User-Agent (e.g. MONEI/MyPartner/0.1.0)"
154+
value={userAgent}
155+
onChangeText={setUserAgent}
156+
autoCapitalize="none"
157+
autoCorrect={false}
158+
/>
127159
<TextInput
128160
style={styles.input}
129161
placeholder="Point of Sale ID (optional)"

0 commit comments

Comments
 (0)