Migration to Yandex Pay 2.0
- Migration plan for the com.yandex.pay:pay library
- Step 1. Update the dependency in the build.gradle files and sync your project
- Step 2. Check the library for compatibility
- Step 3. Use YPay instead of YaPay to get a payment session
- Step 4. Replace the outdated contract with a new launcher
- Step 5. Update the onClickListener for your button
- Step 5. Update the data for the contract
- Step 6. Launch the service
- Step 7. Handle the service operation results
This section describes plans for migrating from the previous versions to the new version: Yandex Pay 2
Migration plan for the com.yandex.pay:pay library
Step 1. Update the dependency in the build.gradle files and sync your project
dependencies {
implementation "com.yandex.pay:pay"
}
Step 2. Check the library for compatibility
If your minSdkVersion
is 23 or lower, see info about support for lower device versions
Step 3. Use YPay instead of YaPay to get a payment session
Use the new object along with the YPay.getYandexPaymentSession()
function instead of the deprecated YaPay.getPaymentSession()
one.
Note
When using this function in Java, you need to pass one more additional sessionKey
parameter.
The parameter is optional for Kotlin.
Step 4. Replace the outdated contract with a new launcher
Use the new YPayLauncher
instead of contract registration
//old
val launcher = registerForActivityResult(YPayContract()){
//do something
}
//new
val launcher = YPayLauncher(this){
//do something
}
//old
ActivityResultLauncher<YPayContractParams> launcher = registerForActivityResult(YPayContract()){
//do something
}
//new
YPayLauncher launcher = new YPayLauncher(this){
//do something
}
Step 5. Update the onClickListener for your button
If you use the Yandex Pay button, you need to update the click listener by passing the previously updated YPayLauncher
to it.
//old
yPayButton.setOnClickListener(YPayButton.OnClickListener {
// do something
})
//new
yPayButton.setOnClickListener(newLauncher){
// do something
}
//old
yPayButton.setOnClickListener(() -> {
// do something
});
//new
yPayButton.setOnClickListener(launcher, yPayButtonLauncher -> {
// call yPayButtonLauncher.launch() for launch service
});
Now, you can launch the service with yPayButtonLauncher
Step 5. Update the data for the contract
In version 2.0, the contract input parameters have been updated. You can now use different payment methods. For details, see Getting started.
Select a convenient payment method and update the input parameters:
//old
val paymentData = PaymentData(...)
//new
val pspLikePaymentData = PaymentData.PaymentUrlFlowData(...)
//old
PaymentData paymentData = new PaymentData(...)
//new
PaymentData pspLikePaymentData = new PaymentData.PaymentUrlFlowData(...)
Step 6. Launch the service
Depending on the payment method and launch format you selected, run the launcher by following the instructions.