Getting Started
Artifact access
In order to seamlessly integrate with our Web SDK artifact, you are required to configure your package manager client by using the following steps.
Configure .npmrc file
- Open or create a
.npmrc
file in the root directory of your project. - Add the following line to the
.npmrc
file:
@paysafe:registry=https://repository.paysafe.com
Save Changes
Save the changes to the .npmrc
file.
Summary
With the .npmrc
file configured, your client will use the specified registry to access the Web SDK from our
Artifactory registry.
If you encounter any issues or have "questions regarding artifact access, contact our team.
Installation
Once you have set up your project to access the artifact, you can install it the SDK and start using it.
- npm
- yarn
- npm (prior to version 7)
npm install @paysafe/paysafe-wallet-saas-web
yarn add @paysafe/paysafe-wallet-saas-web @paysafe/paysafe-wallet-saas-screening-web
npm install @paysafe/paysafe-wallet-saas-web @paysafe/paysafe-wallet-saas-screening-web
Dependencies
The SDK has the following peer dependencies to keep in mind:
- @paysafe/paysafe-wallet-saas-screening-web
Usage
First, you need to import the Wallet
and get a reference to its instance.
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const wallet = Wallet.getInstance();
Type declaration files are available as well and you can import them from the respective module!
In this case you import the Wallet
type from the wallet module.
Configure SDK
In order to use the SDK, you need to configure it, so it can reuse the provided configuration for the lifecycle of
your application. This is done by calling the configure
method of the Wallet
.
import { ApiEnvironment } from '@paysafe/paysafe-wallet-saas-web/wallet';
const sdkConfiguration = {
apiEnvironment: ApiEnvironment.Production, /* the environment that directs the calls to the appropriate Paysafe Wallet API */
configToken: 'demoConfigToken' /* the config token you have received from Paysafe Wallet API */
};
wallet
.configure(sdkConfiguration)
.then(configureResult => console.log('Configure result', configureResult));
The values of ApiEnvironment
and their respective base urls are:
Production
: https://api.paysafe.com/Test
: https://api.test.paysafe.com/
The configToken
is a token that you have received from Paysafe Wallet API in advance. This means that in order to
configure the SDK, you must have already sent an HTTP request for fetching the configToken
.
Authenticate User
In order to use the Paysafe Wallet API, you need to authenticate the user for whom the wallet operations from the
SDK would apply. This is done by calling the authenticate
method of the Wallet
.
const authenticationConfiguration = {
accessToken: this.accessToken /* the user accessToken you have received from Paysafe Wallet API */
};
wallet
.authenticate(authenticationConfiguration)
.then(authenticationResult => console.log('Authentication result', authenticationResult));
The accessToken
is a token that you have received from Paysafe Wallet API in advance. This means that in order to
authenticate a user in the SDK, you must have already sent an HTTP request for fetching the accessToken
.
Wallet Operations
If the Configure SDK and the Authenticate operations were successful, you can start using the SDK for wallet operations!
Example:
wallet.getProfileService().getProfile()
.then(customerInfo => console.log('Customer info', customerInfo))
.catch(error => console.error(error));
Examples for Angular / React
Examples of integrating the Web SDK with Angular or React applications.
- Angular
- React
import { Component, OnInit } from '@angular/core';
import { ApiEnvironment, AuthenticationResult, ConfigurationResult, Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
import { Account, CustomerInfo } from '@paysafe/paysafe-wallet-saas-web/profile';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
private wallet: Wallet = Wallet.getInstance();
private customerInfo: CustomerInfo;
private accounts: Account[];
ngOnInit(): void {
this.setupSdk();
}
private async setupSdk(): Promise<void> {
try {
// Configure the wallet and log the result
const configurationResult = await this.configureWallet();
console.log('Configuration result', configurationResult);
// Authenticate the wallet and log the result
const authenticationResult = await this.authenticateWallet();
console.log('Authentication result', authenticationResult);
// Fetch customerInfo and accounts concurrently using Promise.all
const [fetchedCustomerInfo, fetchedAccounts] = await Promise.all([this.getCustomerInfo(), this.getAccounts()]);
// Set state with the fetched data
this.customerInfo = fetchedCustomerInfo;
this.accounts = fetchedAccounts;
} catch (error) {
// Handle errors during the asynchronous operations
console.error('Error in setupSdk:', error);
}
}
configureWallet(): Promise<ConfigurationResult> {
return this.wallet.configure({
apiEnvironment: ApiEnvironment.Production,
configToken: 'configToken'
});
};
authenticateWallet(): Promise<AuthenticationResult> {
return this.wallet.authenticate({
accessToken: 'accessToken'
});
};
getCustomerInfo(): Promise<CustomerInfo> {
return this.wallet.getProfileService().getProfile();
};
getAccounts(): Promise<Account[]> {
return this.wallet.getProfileService().getAccounts();
};
}
import React, { useEffect, useState } from 'react';
import { ApiEnvironment, AuthenticationResult, ConfigurationResult, Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
import { CustomerInfo } from '@paysafe/paysafe-wallet-saas-web/profile';
const App: React.FC = () => {
const [wallet] = useState(() => Wallet.getInstance());
const [customerInfo, setCustomerInfo] = useState <CustomerInfo | null> (null);
const configureWallet = (): Promise<ConfigurationResult> => {
return wallet.configure({
apiEnvironment: ApiEnvironment.Production,
configToken: 'configToken'
});
};
const authenticateWallet = (): Promise<AuthenticationResult> => {
return wallet.authenticate({
accessToken: 'accessToken'
});
};
const getCustomerInfo = (): Promise<CustomerInfo> => {
return wallet.getProfileService().getProfile();
};
useEffect(() => {
const setupSdk = async () => {
try {
// Configure the wallet and log the result
const configurationResult = await configureWallet();
console.log('Configuration result', configurationResult);
// Authenticate the wallet and log the result
const authenticationResult = await authenticateWallet();
console.log('Authentication result', authenticationResult);
// Fetch customerInfo
const fetchedCustomerInfo = await getCustomerInfo();
// Set state with the fetched customer info
setCustomerInfo(fetchedCustomerInfo);
} catch (error) {
// Handle errors during the asynchronous operations
console.error('Error in setupSdk:', error);
}
};
setupSdk();
}, []);
}
export default App;
Wallet
The Wallet module is the main module of the SDK. It provides the implementation for the Wallet
instance, along with
the necessary models.
All SDK features are exposed through the Wallet
instance. All services and API operations are accessible
through it.
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const wallet = Wallet.getInstance();
Get Profile Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const profileService = Wallet.getInstance().getProfileService();
Get Transaction History Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const transactionHistoryService = Wallet.getInstance().getTransactionHistoryService();
Get Authorization History Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const authorizationHistoryService = Wallet.getInstance().getAuthorizationHistoryService();
Get Payment Instrument Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const paymentInstrumentService = Wallet.getInstance().getPaymentInstrumentService();
Get Customer Verification Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const customerVerificationService = Wallet.getInstance().getCustomerVerificationService();
Get Deposit Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const depositService = Wallet.getInstance().getDepositService();
Get Withdrawal Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const withdrawalService = Wallet.getInstance().getWithdrawalService();
Get Transfer Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const transferService = Wallet.getInstance().getTransferService();
Get Currency Exchange Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const currencyExchangeService = Wallet.getInstance().getCurrencyExchangeService();
Get Prepaid Card Service
import { Wallet } from '@paysafe/paysafe-wallet-saas-web/wallet';
const cardService = Wallet.getInstance().getCardService();