Fetch Access Token Details
Overview
+-------------+ +----------+ +------------+
| Customer |----(1)--->| Customer |----(2)--->| PayMitto |
| Application |<---(4)----| API |<---(3)----| API |
+-------------+ +----------+ +------------+
|
| +------------+
-----------(5)--->| PayMitto |
| SDK |
+------------+- Customer application makes a network request to the Customer API to initiate the creation of an access token for the PayMitto SDK
- Customer API makes a network request to the PayMitto API to create an access token for the PayMitto SDK
- PayMitto API returns the access token details or an error
- Customer API returns the access token details or an error
- Customer application returns the access token details or throws an error
Contract
- Called when the SDK requests authentication.
- Must resolve to PayMittoTokenResponse on success or PayMittoError on failure.
Return Type
See PayMittoTokenResponse and PayMittoError for detailed type documentation.
export interface PayMittoTokenResponse {
accessToken: string;
expiresIn: number;
scope: string;
tokenType: string;
}
export interface PayMittoError {
code: string;
message: string;
}Sample Implementation
import type { PayMittoTokenResponse, PayMittoError } from 'react-native-paymitto-sdk';
export const fetchAccessTokenDetails = async (): Promise<PayMittoTokenResponse | PayMittoError> => {
const url = 'https://example.com/v1/oauth/token';
const response = await fetch(url, { method: 'POST' });
if (!response.ok) {
return { code: 'UNSUCCESSFUL_RESPONSE', message: String(response.status) };
}
return (await response.json()) as PayMittoTokenResponse;
};
...
import React from 'react';
import { Button, View } from 'react-native';
import {
startSDK,
PayMittoEnvironment
} from 'react-native-paymitto-sdk';
export default function App() {
const onPress = () => {
startSDK({
configuration: { environment: PayMittoEnvironment.Sandbox },
fetchAccessTokenDetails: fetchAccessTokenDetails,
...
};
return (
<View style={{ padding: 24 }}>
<Button title="Start PayMitto" onPress={onPress} />
</View>
);
}
