Skip to content

Custom localization #54

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import ru.tinkoff.acquiring.sdk.CreditCard;
import ru.tinkoff.acquiring.sdk.ICameraCardScanner;
import ru.tinkoff.acquiring.sdk.ICreditCard;
import ru.tinkoff.acquiring.sdk.Language;
import ru.tinkoff.acquiring.sdk.TAcqIntentExtra;

/**
* @author Vitaliy Markus
Expand All @@ -22,6 +24,7 @@ public void startActivityForScanning(Fragment fragment, int requestCode) {
Intent scanIntent = createIntent(fragment.getActivity());
fragment.startActivityForResult(scanIntent, requestCode);
}

@Override
public boolean hasResult(@NonNull Intent data) {
return data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT);
Expand Down Expand Up @@ -52,7 +55,20 @@ private Intent createIntent(Activity activity) {
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false);
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false);
scanIntent.putExtra(CardIOActivity.EXTRA_SUPPRESS_CONFIRMATION, true);
setLanguageOrLocale(activity, scanIntent);
return scanIntent;
}

private void setLanguageOrLocale(Activity activity, Intent scanIntent) {
Intent intent = activity.getIntent();
if (intent == null) {
return;
}
int languageExtra = intent.getIntExtra(TAcqIntentExtra.EXTRA_LANGUAGE, -1);
if (languageExtra != -1) {
Language language = Language.values()[languageExtra];
scanIntent.putExtra(CardIOActivity.EXTRA_LANGUAGE_OR_LOCALE, language.toString());
}
}
}

1 change: 1 addition & 0 deletions core/src/main/java/ru/tinkoff/acquiring/sdk/Money.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private String formatFractionalPart(long fractional) {
return String.format("%02d", fractional);
}

@Deprecated
public String toHumanReadableString() {
return toString() + " P";
}
Expand Down
15 changes: 4 additions & 11 deletions payment/src/main/java/ru/tinkoff/acquiring/payment/TinkoffPay.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
package ru.tinkoff.acquiring.payment

import android.app.Activity
import ru.tinkoff.acquiring.sdk.AcquiringSdk
import ru.tinkoff.acquiring.sdk.CardData
import ru.tinkoff.acquiring.sdk.CardsArrayBundlePacker
import ru.tinkoff.acquiring.sdk.Money
import ru.tinkoff.acquiring.sdk.PayFormActivity
import ru.tinkoff.acquiring.sdk.PayFormStarter
import ru.tinkoff.acquiring.sdk.PaymentInfoBundlePacker
import ru.tinkoff.acquiring.sdk.ThreeDsBundlePacker
import ru.tinkoff.acquiring.sdk.*
import ru.tinkoff.acquiring.sdk.requests.InitRequestBuilder

/**
Expand Down Expand Up @@ -78,10 +71,10 @@ class TinkoffPay constructor(
private fun PayFormStarter.addPaymentUiData(paymentDataUi: PaymentDataUi): PayFormStarter {
paymentDataUi.apply {
if (card != null && paymentInfo != null) {
intent.putExtra(PayFormActivity.EXTRA_CARD_DATA, CardsArrayBundlePacker().pack(arrayOf(paymentDataUi.card)))
intent.putExtra(PayFormActivity.EXTRA_PAYMENT_INFO, PaymentInfoBundlePacker().pack(paymentDataUi.paymentInfo))
intent.putExtra(TAcqIntentExtra.EXTRA_CARD_DATA, CardsArrayBundlePacker().pack(arrayOf(paymentDataUi.card)))
intent.putExtra(TAcqIntentExtra.EXTRA_PAYMENT_INFO, PaymentInfoBundlePacker().pack(paymentDataUi.paymentInfo))
} else if (threeDsData != null) {
intent.putExtra(PayFormActivity.EXTRA_THREE_DS, ThreeDsBundlePacker().pack(threeDsData))
intent.putExtra(TAcqIntentExtra.EXTRA_THREE_DS, ThreeDsBundlePacker().pack(threeDsData))
}
}
return this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import ru.tinkoff.acquiring.sample.SettingsSdkManager;
import ru.tinkoff.acquiring.sample.adapters.BooksListAdapter;
import ru.tinkoff.acquiring.sdk.AttachCardFormActivity;
import ru.tinkoff.acquiring.sdk.Language;
import ru.tinkoff.acquiring.sdk.OnAttachCardListener;
import ru.tinkoff.acquiring.sdk.inflate.attach.AttachCellType;

Expand Down Expand Up @@ -83,7 +84,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
.prepare(params.customerKey, settings.getCheckType(), settings.isCustomKeyboardEnabled(), params.customerEmail)
.setTheme(settings.resolveAttachCardStyle())
.setCameraCardScanner(settings.getCameraScanner())
.setDesignConfiguration(AttachCellType.ATTACH_BUTTON, AttachCellType.SECURE_LOGOS, AttachCellType.PAYMENT_CARD_REQUISITES)
// .setDesignConfiguration(AttachCellType.ATTACH_BUTTON, AttachCellType.SECURE_LOGOS, AttachCellType.PAYMENT_CARD_REQUISITES)
.startActivityForResult(this, ATTACH_CARD_REQUEST_CODE);
return true;
case R.id.menu_action_about:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import ru.tinkoff.acquiring.sample.SettingsSdkManager;
import ru.tinkoff.acquiring.sdk.GooglePayParams;
import ru.tinkoff.acquiring.sdk.Item;
import ru.tinkoff.acquiring.sdk.Language;
import ru.tinkoff.acquiring.sdk.Money;
import ru.tinkoff.acquiring.sdk.OnPaymentListener;
import ru.tinkoff.acquiring.sdk.PayFormActivity;
Expand Down Expand Up @@ -137,7 +138,7 @@ protected void initPayment(final Money amount,
//.setReceipt(createReceipt())
//.setData(createData())
.setTheme(settings.resolveStyle())
.setDesignConfiguration(PayCellType.PAYMENT_CARD_REQUISITES, PayCellType.PAY_BUTTON, PayCellType.SECURE_LOGOS)
// .setDesignConfiguration(PayCellType.PAYMENT_CARD_REQUISITES, PayCellType.PAY_BUTTON, PayCellType.SECURE_LOGOS)
.setGooglePayParams(settings.isGooglePayEnabled() ? googlePayParams : null)
.startActivityForResult(this, REQUEST_CODE_PAY);
}
Expand Down
51 changes: 51 additions & 0 deletions sample/src/main/res/raw/custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"Pay.Title": "Оплата",
"Pay.Card.NewCard": "Новая карта",
"Pay.Card.SavedCard": "Сохраненная карта",
"Pay.Card.ChangeCard": "Другая",
"Pay.Card.ChooseLinkedCard": "Выберите карту из привязанных",
"Pay.Card.PanHint": "Номер карты",
"Pay.Card.PanHint.Recurrent": "Выберите карту из привязанных",
"Pay.Card.ExpireDateHint": "ММ/ГГ",
"Pay.Card.CvcHint": "CVC",
"Pay.Money.Amount.Label": "На сумму:",
"Pay.Email": "E-mail для квитанции",
"Pay.PayButton": "Оплатить",
"Pay.Dialog.Error.Title": "Ошибка",
"Pay.Dialog.Error.FallbackMessage": "Что-то пошло не так",
"Pay.Dialog.Error.Network": "Вероятно, соединение с интернетом прервано, попробуйте позже",
"Pay.Dialog.Error.AcceptButton": "OK",
"Pay.Dialog.Validation.Title": " ",
"Pay.Dialog.Validation.InvalidEmail": "Введен некорректный e-mail",
"Pay.Dialog.Validation.InvalidCard": "Введены некорректные данные карты",
"Pay.Dialog.Progress.PayMessage": "Оплата…",
"Pay.Dialog.CardScan.Nfc": "Сканировать по NFC",
"Pay.Dialog.CardScan.Camera": "Сканировать камерой",
"Pay.Dialog.Cvc.Message": "Для совершения платежа, введите CVC",
"Pay.Dialog.Cvc.AcceptButton": "OK",
"Pay.Nfc.Fail": "Не удалось распознать карту",
"Pay.NoScanProviders": "Отсутствуют провайдеры для сканирования",
"ConfirmationLoop.Title": "Оплата",
"ConfirmationLoop.Description": "Для подтверждения привязки карты мы списали и вернули небольшую сумму (до 1,99 ₽)\nПожалуйста, укажите ее с точностью до копеек",
"ConfirmationLoop.Amount": "Заблокированная сумма",
"ConfirmationLoop.Dialog.Validation.InvalidAmount": "Введите корректную сумму в копейках",
"ConfirmationLoop.CheckButton": "Проверить",
"Confirmation3DS.Title": "Оплата",
"AddCard.Title": "Добавление карты",
"AddCard.AddCardButton": "Добавить",
"AddCard.Dialog.Error.Title": "Ошибка",
"AddCard.Dialog.Error.Network": "Вероятно, соединение с интернетом прервано, попробуйте позже",
"AddCard.Nfc.Fail": "Не удалось распознать карту",
"AddCard.Dialog.Progress.AddCardMessage": "Добавление карты...",
"AddCard.Dialog.Error.FallbackMessage": "Что-то пошло не так",
"AddCard.NoScanProviders": "Отсутствуют провайдеры для сканирования",
"CardList.Title": "Выберите карту",
"CardList.NewCard": "Ввести данные новой карты",
"CardList.Delete": "Удалить",
"CardList.RemoveCard.FailMessage": "Не удалось удалить карту, попробуйте позже",
"Nfc.Title": " ",
"Nfc.Description": "Поднесите карту\nк задней крышке телефона",
"Nfc.CloseButton": "Закрыть",
"Nfc.Dialog.Disable.Title": "NFC выключен",
"Nfc.Dialog.Disable.Message": "Для сканирования карты необходимо включить NFC"
}
8 changes: 2 additions & 6 deletions sample/src/main/res/values/style_custom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
<item name="acqPayEmailStyle">@style/AcquiringPayEmailStyle.Custom</item>
<item name="acqPayAmountPosition">overFields</item>
<item name="acqPayButtonAndIconPosition">iconsUnderFieldsButtonOnBottom</item>
<item name="acqPayFormTitle">@string/acq_screen_title_custom</item>
<item name="acqPayWithAmountFormat">@string/acq_pay_with_amount_custom</item>
<item name="acqMoneyAmountFormat">@string/acq_money_amount_format_custom</item>
<item name="acqKeyboardStyle">@style/AcquiringKeyboardStyle.Custom</item>
</style>

<style name="AcquiringTheme.Custom.AttachCard">
<item name="acqPayFormTitle">@string/attachment_toolbar_title</item>
<item name="acqPayAmountPosition">overFields</item>
<item name="acqPayTitleStyle">@style/AcquiringPayTitleStyle.Custom.AttachCard</item>
<item name="acqPayDescriptionStyle">@style/AcquiringPayDescriptionStyle.Custom.AttachCard</item>
<item name="acqPayDescriptionStyle">@style/AcquiringPayDescriptionStyle.Custom.AttachCard
</item>
<item name="acqButtonStyle">@style/AcquiringPayButtonStyle.Custom.AttachCard</item>
</style>

<style name="AcquiringTheme.AttachCard">
<item name="acqPayFormTitle">@string/attachment_toolbar_title</item>
<item name="acqPayAmountPosition">overFields</item>
<item name="acqPayTitleStyle">@style/AcquiringPayTitleStyle.AttachCard</item>
<item name="acqPayDescriptionStyle">@style/AcquiringPayDescriptionStyle.AttachCard</item>
Expand Down
2 changes: 1 addition & 1 deletion ui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
api("com.google.android.gms:play-services-wallet:11.6.2") {
exclude module: 'support-v4'
}

implementation "com.google.code.gson:gson:$gsonVersion"
api project(':core')
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,49 @@
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.MenuItem;
import android.widget.Toast;

import ru.tinkoff.acquiring.sdk.localization.AsdkLocalization;
import ru.tinkoff.acquiring.sdk.localization.HasAsdkLocalization;

/**
* @author Vitaliy Markus
*/
public class AttachCardFormActivity extends AppCompatActivity implements IAttachCardFormActivity {

public static final int RESULT_ERROR = 500;
static final String EXTRA_ERROR = "error";

static final String EXTRA_TERMINAL_KEY = "terminal_key";
static final String EXTRA_PASSWORD = "password";
static final String EXTRA_PUBLIC_KEY = "public_key";

static final String EXTRA_CUSTOMER_KEY = "customer_key";
static final String EXTRA_CHECK_TYPE = "check_type";
static final String EXTRA_CUSTOM_KEYBOARD = "keyboard";
static final String EXTRA_DATA = "data";
static final String EXTRA_THEME = "theme";
static final String EXTRA_CAMERA_CARD_SCANNER = "card_scanner";
static final String EXTRA_CARD_ID = "card_id";
static final String EXTRA_EMAIL = "email";
static final String EXTRA_DESIGN_CONFIGURATION = "design_configuration";

private DialogsManager dialogsManager;
private AcquiringSdk sdk;

private boolean useCustomKeyboard;
private String cardId;
private AsdkLocalizationProperty asdkLocalization;

public static AttachCardFormStarter init(String terminalKey, String password, String publicKey) {
return new AttachCardFormStarter(terminalKey, password, publicKey);
}

public static void dispatchResult(int resultCode, Intent data, OnAttachCardListener listener) {
if (resultCode == RESULT_OK) {
listener.onSuccess(data.getStringExtra(AttachCardFormActivity.EXTRA_CARD_ID));
listener.onSuccess(data.getStringExtra(TAcqIntentExtra.EXTRA_CARD_ID));
} else if (resultCode == RESULT_CANCELED) {
listener.onCancelled();
} else if (resultCode == RESULT_ERROR) {
listener.onError((Exception) data.getSerializableExtra(EXTRA_ERROR));
listener.onError((Exception) data.getSerializableExtra(TAcqIntentExtra.EXTRA_ERROR));
}
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

asdkLocalization = new AsdkLocalizationProperty(this);
Intent intent = getIntent();
initActivity(intent);
dialogsManager = new DialogsManager(this);
sdk = createSdk(intent);
useCustomKeyboard = intent.getBooleanExtra(EXTRA_CUSTOM_KEYBOARD, false);
useCustomKeyboard = intent.getBooleanExtra(TAcqIntentExtra.EXTRA_CUSTOM_KEYBOARD, false);

if (savedInstanceState == null) {
addAttachCardFragment();
Expand Down Expand Up @@ -99,7 +87,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
public void success() {
hideProgressDialog();
Intent data = new Intent();
data.putExtra(EXTRA_CARD_ID, cardId);
data.putExtra(TAcqIntentExtra.EXTRA_CARD_ID, cardId);
setResult(RESULT_OK, data);
finish();
}
Expand All @@ -112,7 +100,7 @@ public void cancel() {

@Override
public void showProgressDialog() {
dialogsManager.showProgressDialog(getString(R.string.acq_progress_dialog_attach_card_text));
dialogsManager.showProgressDialog(getAsdkLocalization().addCardDialogProgressAddCardMessage);
}

@Override
Expand All @@ -129,7 +117,7 @@ public void exception(Throwable throwable) {
}

Intent data = new Intent();
data.putExtra(EXTRA_ERROR, throwable);
data.putExtra(TAcqIntentExtra.EXTRA_ERROR, throwable);
setResult(RESULT_ERROR, data);
finish();
}
Expand All @@ -150,15 +138,15 @@ public void start3DS(ThreeDsData data) {
public void showErrorDialog(Exception e) {
String message = e.getMessage();
if (TextUtils.isEmpty(message)) {
message = getString(R.string.acq_default_error_message);
message = getAsdkLocalization().addCardDialogErrorFallbackMessage;
}
dialogsManager.showErrorDialog(getString(R.string.acq_default_error_title), message);
dialogsManager.showErrorDialog(getAsdkLocalization().addCardDialogErrorTitle, message);
}

@Override
public void noNetwork() {
String title = getString(R.string.acq_default_error_title);
String message = getString(R.string.acq_network_error_message);
String title = getAsdkLocalization().addCardDialogErrorTitle;
String message = getAsdkLocalization().addCardDialogErrorNetwork;
DialogInterface.OnClickListener onClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Expand Down Expand Up @@ -215,7 +203,7 @@ boolean shouldUseCustomKeyboard() {
}

private void initActivity(Intent intent) {
int theme = intent.getIntExtra(EXTRA_THEME, 0);
int theme = intent.getIntExtra(TAcqIntentExtra.EXTRA_THEME, 0);
if (theme != 0) {
setTheme(theme);
}
Expand All @@ -224,16 +212,13 @@ private void initActivity(Intent intent) {
setContentView(R.layout.acq_activity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

TypedValue tv = new TypedValue();
getTheme().resolveAttribute(R.attr.acqPayFormTitle, tv, true);
String title = getResources().getString(tv.resourceId);
setTitle(title);
setTitle(getAsdkLocalization().addCardTitle);
}

private AcquiringSdk createSdk(Intent intent) {
String terminalKey = intent.getStringExtra(EXTRA_TERMINAL_KEY);
String password = intent.getStringExtra(EXTRA_PASSWORD);
String publicKey = intent.getStringExtra(EXTRA_PUBLIC_KEY);
String terminalKey = intent.getStringExtra(TAcqIntentExtra.EXTRA_TERMINAL_KEY);
String password = intent.getStringExtra(TAcqIntentExtra.EXTRA_PASSWORD);
String publicKey = intent.getStringExtra(TAcqIntentExtra.EXTRA_PUBLIC_KEY);
return new AcquiringSdk(terminalKey, password, publicKey);
}

Expand All @@ -252,4 +237,9 @@ private void addAttachCardFragment() {
.commit();

}

@Override
public AsdkLocalization getAsdkLocalization() {
return asdkLocalization.getAsdkLocalization();
}
}
Loading