Skip to content

Commit

Permalink
Version update: 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
drukarev committed Dec 18, 2019
1 parent 1b6f00d commit fd6efcb
Show file tree
Hide file tree
Showing 58 changed files with 1,286 additions and 350 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### 3.0.0
- Change public api. PaymentParameters and SavedBankCardPaymentParameters now have new required parameter - savePaymentMethod.
- Add ability to save payment methods for recurring payments.

### 2.4.1
2019-11-15
- Fix screen artifacts on closing mSDK.
Expand Down
22 changes: 18 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

# Документация

Android Checkout mobile SDK - версия 2.4.1 ([changelog](https://github.com/yandex-money/yandex-checkout-android-sdk/blob/master/CHANGELOG.md))
Android Checkout mobile SDK - версия 3.0.0 ([changelog](https://github.com/yandex-money/yandex-checkout-android-sdk/blob/master/CHANGELOG.md))

* [Подключение зависимостей](#подключение-зависимостей)
* [Подключение через Gradle](#подключение-через-gradle)
Expand Down Expand Up @@ -41,7 +41,7 @@ repositories {
}
dependencies {
implementation 'com.yandex.money:checkout:2.4.1'
implementation 'com.yandex.money:checkout:3.0.0'
}
```

Expand Down Expand Up @@ -102,6 +102,7 @@ dependencies {
* subtitle (String) - описание товара;
* clientApplicationKey (String) - токен магазина, полученный в Яндекс.Кассе;
* shopId (String) - идентификатор магазина в Яндекс.Кассе.
* savePaymentMethod (SavePaymentMethod) - настройка сохранения платёжного метода. Сохранённые платёжные методы можно использовать для проведения рекуррентных платежей.

Необязательные:
* paymentMethodTypes (Set of PaymentMethodType) - ограничения способов оплаты. Если оставить поле пустым или передать в него null,
Expand All @@ -115,6 +116,11 @@ dependencies {
* value (BigDecimal) - сумма;
* currency (Currency) - валюта.

Значения `SavePaymentMethod`:
* ON - Сохранить платёжный метод для проведения рекуррентных платежей. Пользователю будут доступны только способы оплаты, поддерживающие сохранение. На экране контракта будет отображено сообщение о том, что платёжный метод будет сохранён.
* OFF - Не сохранять платёжный метод.
* USER_SELECTS - Пользователь выбирает, сохранять платёжный метод или нет. Если метод можно сохранить, на экране контракта появится переключатель.

Значения `PaymentMethodType`:
* YANDEX_MONEY - оплата произведена с кошелька Яндекс.денег;
* BANK_CARD - оплата произведена с банковской карты;
Expand Down Expand Up @@ -144,7 +150,8 @@ class MyActivity extends android.support.v7.app.AppCompatActivity {
"Название товара",
"Описание товара",
"live_AAAAAAAAAAAAAAAAAAAA",
"12345"
"12345",
SavePaymentMethod.OFF
);
Intent intent = Checkout.createTokenizeIntent(this, paymentParameters);
startActivityForResult(intent, REQUEST_CODE_TOKENIZE);
Expand Down Expand Up @@ -174,11 +181,17 @@ class MyActivity extends android.support.v7.app.AppCompatActivity {
* clientApplicationKey (String) - токен магазина, полученный в Яндекс.Кассе;
* shopId (String) - идентификатор магазина в Яндекс.Кассе;
* paymentId (String) - идентификатор платежа.
* savePaymentMethod (SavePaymentMethod) - настройка сохранения платёжного метода. Сохранённые платёжные методы можно использовать для проведения рекуррентных платежей.

Поля класса `Amount`:
* value (BigDecimal) - сумма;
* currency (Currency) - валюта.

Значения `SavePaymentMethod`:
* ON - Сохранить платёжный метод для проведения рекуррентных платежей. Пользователю будут доступны только способы оплаты, поддерживающие сохранение. На экране контракта будет отображено сообщение о том, что платёжный метод будет сохранён.
* OFF - Не сохранять платёжный метод.
* USER_SELECTS - Пользователь выбирает, сохранять платёжный метод или нет. Если метод можно сохранить, на экране контракта появится переключатель.

```java
class MyActivity extends android.support.v7.app.AppCompatActivity {

Expand All @@ -191,7 +204,8 @@ class MyActivity extends android.support.v7.app.AppCompatActivity {
"Описание товара",
"live_AAAAAAAAAAAAAAAAAAAA",
"12345",
"paymentId"
"paymentId",
SavePaymentMethod.OFF
);
Intent intent = Checkout.createSavedCardTokenizeIntent(this, parameters);
startActivityForResult(intent, REQUEST_CODE_TOKENIZE);
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ allprojects {
task clean(type: Delete) {
delete rootProject.buildDir
}

6 changes: 3 additions & 3 deletions common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
apply from: rootProject.file("sensitive.gradle")

ext {
versionMajor = 2
versionMinor = 4
versionPatch = 1
versionMajor = 3
versionMinor = 0
versionPatch = 0

versionAlpha = null

Expand Down
4 changes: 4 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
android:name=".impl.CheckoutActivity"
android:theme="@style/ym_Theme.Translucent" />

<activity
android:name=".impl.contract.SavePaymentMethodInfoActivity"
android:theme="@style/ym_Theme" />

<meta-data
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.os.Parcelable
import android.support.annotation.Keep
import kotlinx.android.parcel.Parcelize
import ru.yandex.money.android.sdk.utils.getAllPaymentMethods
import java.io.Serializable

/**
* Wrapper for payment parameters. This class is used in [Checkout.createTokenizeIntent].
Expand All @@ -36,6 +35,7 @@ import java.io.Serializable
* @param subtitle description of the goods to be bought.
* @param clientApplicationKey merchant token from Yandex.Checkout.
* @param shopId shop id from Yandex.Checkout.
* @param savePaymentMethod setting for saving payment method (see [SavePaymentMethod]]).
* @param paymentMethodTypes (optional) set of permitted method types. Empty set or parameter absence means that all
* payment methods are allowed. See [PaymentMethodType].
* @param gatewayId (optional) your gateway id from Yandex.Money.
Expand All @@ -53,6 +53,7 @@ data class PaymentParameters
@Keep val subtitle: String,
@Keep val clientApplicationKey: String,
@Keep val shopId: String,
@Keep val savePaymentMethod: SavePaymentMethod,
@Keep val paymentMethodTypes: Set<PaymentMethodType> = getAllPaymentMethods(),
@Keep val gatewayId: String? = null,
@Keep val customReturnUrl: String? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
* Copyright © 2019 NBCO Yandex.Money LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the “Software”), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package ru.yandex.money.android.sdk

import android.support.annotation.Keep

/**
* Setting for saving payment method. If payment method is saved, shop can make recurring payments with a token,
* received from [Checkout.createTokenizationResult].
*
* There are three options for this setting:
* [ON] - always save payment method. User can select only from payment methods, that allow saving.
* On the contract screen user will see a message about saving his payment method.
* [OFF] - don't save payment method. User can select from all of the available payment methods.
* [USER_SELECTS] - user chooses to save payment method (user will have a switch to change
* selection, if payment method can be saved).
*/
@Keep
enum class SavePaymentMethod {
/**
* Always save payment method. User can select only from payment methods, that allow saving.
* On the contract screen user will see a message about saving his payment method.
*/
@Keep
ON,
/**
* Don't save payment method. User can select from all of the available payment methods.
*/
@Keep
OFF,
/**
* User chooses to save payment method (user will have a switch to change selection,
* if payment method can be saved).
*/
@Keep
USER_SELECTS
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import kotlinx.android.parcel.Parcelize
* @param clientApplicationKey merchant token from Yandex.Checkout.
* @param shopId shop id from Yandex.Checkout.
* @param paymentMethodId id of previous payment.
* @param savePaymentMethod setting for saving payment method (see [SavePaymentMethod]]).
*/
@[Parcelize SuppressLint("ParcelCreator")]
data class SavedBankCardPaymentParameters
Expand All @@ -44,5 +45,6 @@ data class SavedBankCardPaymentParameters
@Keep val subtitle: String,
@Keep val clientApplicationKey: String,
@Keep val shopId: String,
@Keep val paymentMethodId: String
@Keep val paymentMethodId: String,
@Keep val savePaymentMethod: SavePaymentMethod
) : Parcelable
24 changes: 14 additions & 10 deletions library/src/main/java/ru/yandex/money/android/sdk/impl/AppModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import ru.yandex.money.android.sdk.TestParameters
import ru.yandex.money.android.sdk.UiParameters
import ru.yandex.money.android.sdk.impl.InMemoryColorSchemeRepository.colorScheme
import ru.yandex.money.android.sdk.impl.contract.ContractErrorPresenter
import ru.yandex.money.android.sdk.impl.contract.ContractFormatter
import ru.yandex.money.android.sdk.impl.contract.ContractPresenter
import ru.yandex.money.android.sdk.impl.contract.ContractProgressViewModel
import ru.yandex.money.android.sdk.impl.contract.ContractViewModel
import ru.yandex.money.android.sdk.impl.extensions.toConfirmation
import ru.yandex.money.android.sdk.impl.extensions.getConfirmation
import ru.yandex.money.android.sdk.impl.logging.MsdkLogger
import ru.yandex.money.android.sdk.impl.logging.ReporterLogger
import ru.yandex.money.android.sdk.impl.logging.StubLogger
Expand Down Expand Up @@ -212,8 +213,7 @@ internal object AppModel {
argContext: Context,
paymentParameters: PaymentParameters,
testParameters: TestParameters,
uiParameters: UiParameters,
requestRecurringPayment: Boolean = false
uiParameters: UiParameters
) {

val context = argContext.applicationContext
Expand Down Expand Up @@ -278,7 +278,10 @@ internal object AppModel {

if (mockConfiguration != null) {
val mockPaymentOptionListGateway =
MockPaymentOptionListGateway(mockConfiguration.linkedCardsCount, Fee(service = mockConfiguration.serviceFee))
MockPaymentOptionListGateway(
mockConfiguration.linkedCardsCount,
Fee(service = mockConfiguration.serviceFee)
)
paymentOptionListGateway = mockPaymentOptionListGateway
authorizeUserGateway = MockAuthorizeUserGateway
tokenizeGateway = MockTokenizeGateway(mockConfiguration.completeWithError)
Expand Down Expand Up @@ -326,7 +329,8 @@ internal object AppModel {
httpClient = httpClient,
gatewayId = paymentParameters.gatewayId,
tokensStorage = tokensStorage,
shopToken = paymentParameters.clientApplicationKey
shopToken = paymentParameters.clientApplicationKey,
savePaymentMethod = paymentParameters.savePaymentMethod
)
paymentOptionListGateway = InternetDependentGateway(context, apiV3PaymentOptionListGateway)
if (paymentParameters.paymentMethodTypes.contains(PaymentMethodType.YANDEX_MONEY)) {
Expand Down Expand Up @@ -398,7 +402,9 @@ internal object AppModel {
context = context,
shopTitle = paymentParameters.title,
shopSubtitle = paymentParameters.subtitle,
recurringPaymentsPossible = requestRecurringPayment
getSavePaymentMethodMessageLink = { ContractFormatter.getSavePaymentMethodMessageLink(context, it) },
getSavePaymentMethodSwitchLink = { ContractFormatter.getSavePaymentMethodSwitchLink(context, it) },
requestedSavePaymentMethod = paymentParameters.savePaymentMethod
)
val contractErrorPresenter = ContractErrorPresenter(errorPresenter)
val requestPaymentAuthErrorPresenter = RequestPaymentAuthErrorPresenter(context, errorPresenter)
Expand Down Expand Up @@ -488,10 +494,8 @@ internal object AppModel {
getLoadedPaymentOptionListGateway = getLoadedPaymentOptionListGateway,
tokenizeGateway = tokenizeGateway,
checkPaymentAuthRequiredGateway = checkPaymentAuthRequiredGateway,
convertToConfirmation = {
it.toConfirmation(
paymentParameters.customReturnUrl ?: DEFAULT_REDIRECT_URL
)
getConfirmation = {
it.getConfirmation(paymentParameters.customReturnUrl ?: DEFAULT_REDIRECT_URL)
}
),
presenter = ActionTokenizeReporter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ internal class CheckoutActivity : AppCompatActivity() {
subtitle = cscParameter.subtitle,
clientApplicationKey = cscParameter.clientApplicationKey,
shopId = cscParameter.shopId,
paymentMethodTypes = setOf(PaymentMethodType.BANK_CARD)
paymentMethodTypes = setOf(PaymentMethodType.BANK_CARD),
savePaymentMethod = cscParameter.savePaymentMethod
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* The MIT License (MIT)
* Copyright © 2019 NBCO Yandex.Money LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the “Software”), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
* of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
* following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/

package ru.yandex.money.android.sdk.impl.contract

import android.content.Context
import android.content.Intent
import android.support.v4.content.ContextCompat
import ru.yandex.money.android.sdk.R
import ru.yandex.money.android.sdk.model.AbstractWallet
import ru.yandex.money.android.sdk.model.PaymentOption
import ru.yandex.money.android.sdk.model.Wallet
import ru.yandex.money.android.sdk.utils.getMessageWithLink

internal class ContractFormatter {

companion object {

internal fun getSavePaymentMethodMessageLink(context: Context, paymentOption: PaymentOption): CharSequence {
val linkTextFirstPart: Int
val linkTextSecondPart: Int
if (paymentOption is Wallet || paymentOption is AbstractWallet) {
linkTextFirstPart = R.string.ym_save_payment_method_wallet_message_text_part_1
linkTextSecondPart = R.string.ym_save_payment_method_wallet_message_text_part_2
} else {
linkTextFirstPart = R.string.ym_save_payment_method_bank_card_message_text_part_1
linkTextSecondPart = R.string.ym_save_payment_method_bank_card_message_text_part_2
}

return getLinkForSavePaymentMethodScreen(
context = context,
linkTextFirstPart = linkTextFirstPart,
linkTextSecondPart = linkTextSecondPart,
paymentOption = paymentOption
)
}

internal fun getSavePaymentMethodSwitchLink(context: Context, paymentOption: PaymentOption): CharSequence {
val linkTextFirstPart: Int
val linkTextSecondPart: Int
if (paymentOption is Wallet || paymentOption is AbstractWallet) {
linkTextFirstPart = R.string.ym_save_payment_method_wallet_switch_text_part_1
linkTextSecondPart = R.string.ym_save_payment_method_wallet_switch_text_part_2
} else {
linkTextFirstPart = R.string.ym_save_payment_method_bank_card_switch_text_part_1
linkTextSecondPart = R.string.ym_save_payment_method_bank_card_switch_text_part_2
}

return getLinkForSavePaymentMethodScreen(
context = context,
linkTextFirstPart = linkTextFirstPart,
linkTextSecondPart = linkTextSecondPart,
paymentOption = paymentOption
)
}

private fun getLinkForSavePaymentMethodScreen(
context: Context,
linkTextFirstPart: Int,
linkTextSecondPart: Int,
paymentOption: PaymentOption
): CharSequence {

val screenTitle: Int
val screenText: Int
if (paymentOption is Wallet || paymentOption is AbstractWallet) {
screenTitle = R.string.ym_save_payment_method_wallet_info_title
screenText = R.string.ym_save_payment_method_wallet_info_text
} else {
screenTitle = R.string.ym_save_payment_method_bank_card_info_title
screenText = R.string.ym_save_payment_method_bank_card_info_text
}

return getMessageWithLink(context, linkTextFirstPart, linkTextSecondPart) {
ContextCompat.startActivity(
context, SavePaymentMethodInfoActivity.create(context, screenTitle, screenText)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK), null
)
}
}
}
}
Loading

0 comments on commit fd6efcb

Please sign in to comment.