Withdrawals
Introduction
The Withdrawal service exposes features for managing withdrawals:
- Get Withdrawal Options
- Preview, Create and Confirm a Withdrawal
- Get Withdrawals List
- Get Single Withdrawal
Use the following code to obtain an instance of WithdrawalService
:
- Kotlin
- Swift
val withdrawals = Wallet.getInstance().getWithdrawalService()
import PaysafeWallet
let withdrawals = Wallet.instance.withdrawalService
Get Withdrawal Options
Use getOptions
method to retrieve a list of all available withdrawal options for the customer.
Withdraw options refer to the methods of transferring funds (e.g., bank cards or bank accounts), while instrument types pertain to the specific financial tools or mechanisms used in these transactions (e.g., a concrete bank card or account).
- Kotlin
- Swift
try {
val withdrawalOptions: List<PaymentOptionDetails> = withdrawals.getOptions()
Log.d(TAG, withdrawalOptions.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
withdrawals.getOptions(completion: { result in
switch result {
case .success(let withdrawalOptions):
// Handle withdrawalOptions
case .failure(let error):
// Handle error
}
})
Get Withdrawals List
- Kotlin
- Swift
Use getAll
method to retrieve a list of withdrawals by passing the GetWithdrawalsParameters
.
If no parameters are passed, it will return the last 10 withdrawals by default.
val getWithdrawalsParameters = GetWithdrawalsParameters(
limit = 10,
merchantRefNum = "19481996",
offset = 10,
slipId = "123"
)
try {
val result = withdrawals.getAll(getWithdrawalsParameters)
Log.d(TAG, result.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
Use getAll
method to retrieve a list of withdrawals by passing the GetWithdrawalsParameters
.
If no parameters are passed, it will return the last 10 withdrawals by default.
let getWithdrawalsParameters = Wallet.GetWithdrawalsParameters(limit: nil,
merchantRefNum: "19481996",
offset: nil,
slipID: nil)
withdrawals.getAll(getWithdrawalsParameters: getWithdrawalsParameters, completion: { result in
switch result {
case .success(let withdrawals):
// Handle withdrawals
case .failure(let error):
// Handle error
}
})
Get Single Withdrawal
Use get
method to retrieve a withdrawal by passing its id.
- Kotlin
- Swift
val withdrawalId = "123"
try {
val withdrawal = withdrawals.get(withdrawalId)
Log.d(TAG, withdrawal.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
let withdrawalId = "123"
withdrawals.get(id: withdrawalId, completion: { result in
switch result {
case .success(let withdrawal):
// Handle withdrawal
case .failure(let error):
// Handle error
}
})
Preview Withdrawal
Use preview
method to create a withdrawal for the current customer. Withdrawals are created in PREVIEW
state.
Withdrawals in PREVIEW
state do not create actual transaction in Paysafe Wallet system.
It allows to check withdrawal parameters and display the fees.
- Kotlin
- Swift
To initiate withdrawal you should use WithdrawalRequest
object.
val withdrawalRequest = WithdrawalRequest(
amount = 100,
currencyCode = "USD",
paymentOption = PaymentOptionType.BANK_TRANSFER,
paymentInstrumentReference = PaymentInstrumentReference(
id = "123",
instrumentType = InstrumentType.US_BANK_ACCOUNT
),
merchantRefNum = "19481996",
paymentProperties = null
)
try {
val withdrawalPreview = withdrawals.preview(withdrawalRequest)
Log.d(TAG, withdrawalPreview.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
To initiate withdrawal you should use WithdrawalRequest
object.
let withdrawalRequest = Wallet.WithdrawalRequest(amount: 100,
currencyCode: "USD",
paymentOption: .bankTransfer,
paymentInstrumentReference: .init(id: "123",
instrumentType: .usBankAccount),
merchantRefNum: "19481995",
paymentProperties: nil)
withdrawals.preview(withdrawalRequest: withdrawalRequest, completion: { result in
switch result {
case .success(let withdrawalPreview):
// Handle withdrawalPreview
case .failure(let error):
// Handle error
}
})
Create Withdrawal
Use create
method to perform the required validations and move the withdrawal in PENDING
state.
- Kotlin
- Swift
Use WithdrawalCreate
object to create the withdrawal. Pass the id
from the Withdrawal
object returned by the preview
method.
val withdrawalCreate = WithdrawalCreate(id = "123")
try {
val withdrawal = withdrawals.create(withdrawalCreate)
Log.d(TAG, withdrawal.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
Use WithdrawalCreate
object to create the withdrawal. Pass the id
from the Withdrawal
object returned by the preview
method.
let withdrawalCreate = Wallet.WithdrawalCreate(id: "123")
withdrawals.create(withdrawalCreate: withdrawalCreate, completion: { result in
switch result {
case .success(let withdrawal):
// Handle withdrawal
case .failure(let error):
// Handle error
}
})
Confirm Withdrawal
Use confirm
method to confirm the withdrawal.
This operation might require Strong Customer Authentication (SCA). Please read Strong Customer Authentication for more information on the process.
If the Withdrawal
object returned by confirm
has action: PaymentCompletionAction.SCA
,
the scaDetails
will contain the SCA authentication properties needed to complete the process.
Follow the steps outlined in Submit the SCA Authentication
to confirm the event. After the SCA event is accepted, invoke confirm
method again,
providing scaDetails
in the WithdrawalConfirm
parameter.
- Kotlin
- Swift
Use WithdrawalConfirm
object to create the withdrawal. Pass the id
from the Withdrawal
object returned by the create
method.
val withdrawalConfirm = WithdrawalConfirm(id = "123")
try {
val withdrawal = withdrawals.confirm(withdrawalConfirm)
Log.d(TAG, withdrawal.toString())
} catch (exception: Exception) {
Log.d(TAG, exception.toString())
}
Use WithdrawalConfirm
object to create the withdrawal. Pass the id
from the Withdrawal
object returned by the create
method.
let withdrawalConfirm = Wallet.WithdrawalConfirm(id: "123")
withdrawals.confirm(withdrawalConfirm: withdrawalConfirm, completion: { result in
switch result {
case .success(let withdrawal):
// Handle withdrawal
case .failure(let error):
// Handle error
}
})