Skip to content

Commit

Permalink
Merge pull request #12 from MadBrains/closing_receipt
Browse files Browse the repository at this point in the history
[3.0.1] Add SendClosingReceipt endpoint. Small fixes
  • Loading branch information
mit-73 authored May 17, 2021
2 parents b69ee2f + 9a87ac9 commit 8a0a7f4
Show file tree
Hide file tree
Showing 21 changed files with 315 additions and 24 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ jobs:
- name: 'Install Tools'
run: |
flutter pub global activate melos
flutter pub global activate flutter_plugin_tools
- name: 'Clean Workspace'
run: melos clean
- name: 'Bootstrap Workspace'
run: melos bootstrap
- name: 'Melos Format'
- name: 'Format Code'
run: melos run format
- name: 'Validate Formatting'
run: |
Expand Down
4 changes: 2 additions & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ ide:

scripts:
format: >
melos exec -c 1 -- \
melos exec -c 6 -- \
dartfmt -w .
# Run `dart analyze` in all packages.
Expand All @@ -28,7 +28,7 @@ scripts:

lint:pana: >
melos exec -c 1 --fail-fast --no-private --ignore="*example*" -- \
pana || pub global activate pana
pana

# Additional cleanup lifecycle script, executed when `melos clean` is ran.
postclean: >
Expand Down
5 changes: 5 additions & 0 deletions packages/tinkoff_acquiring/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 3.0.1

* Add SendClosingReceipt endpoint
* Small fixes

# 3.0.0

* **BREAKING**: Splitting the library into two packages:
Expand Down
12 changes: 7 additions & 5 deletions packages/tinkoff_acquiring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<a href="https://madbrains.ru/"><img src="https://firebasestorage.googleapis.com/v0/b/mad-brains-web.appspot.com/o/logo.png?alt=media" width="200" align="right" style="margin: 20px;"/></a>

[Read this in Russian](README.ru.md)
[Read this in Russian][readme_ru]

Acquiring SDK allows you to integrate [Tinkoff Internet Acquiring][acquiring] into mobile applications for iOS and Android platforms.

Expand All @@ -20,8 +20,8 @@ Acquiring SDK allows you to integrate [Tinkoff Internet Acquiring][acquiring] in
Add this to your package's pubspec.yaml file:
```yaml
dependencies:
tinkoff_acquiring: 3.0.0
tinkoff_acquiring_flutter: 3.0.0 # for UI
tinkoff_acquiring: 3.0.1
tinkoff_acquiring_flutter: 3.0.1 # for UI
```
## Before usage
Expand Down Expand Up @@ -58,10 +58,12 @@ final TinkoffAcquiring acquiring = TinkoffAcquiring(

## Example

The [Example](../../example/lib/main.dart) is in the corresponding folder
The [Example][example] is in the corresponding folder

## SDK workflow
<details><img src="https://acdn.tinkoff.ru/static/pages/files/d3cd0230-03a1-47e6-bacf-dfdf9c8c1bea.png"/></details>

[documentation]: https://www.tinkoff.ru/kassa/develop/api/payments/
[acquiring]: https://www.tinkoff.ru/business/internet-acquiring/
[acquiring]: https://www.tinkoff.ru/business/internet-acquiring/
[example]: https://github.com/MadBrains/Tinkoff-Acquiring-SDK-Flutter/tree/main/example
[readme_ru]: https://github.com/MadBrains/Tinkoff-Acquiring-SDK-Flutter/blob/main/packages/tinkoff_acquiring/README.ru.md
9 changes: 5 additions & 4 deletions packages/tinkoff_acquiring/README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Acquiring SDK позволяет интегрировать [Интернет-Э
Для подключения добавьте в файл Pubspec зависимости:
```yaml
dependencies:
tinkoff_acquiring: 3.0.0
tinkoff_acquiring_flutter: 3.0.0 # for UI
tinkoff_acquiring: 3.0.1
tinkoff_acquiring_flutter: 3.0.1 # for UI
```
## Подготовка к работе
Expand Down Expand Up @@ -56,10 +56,11 @@ final TinkoffAcquiring acquiring = TinkoffAcquiring(

## Пример работы

Пример работы SDK доступен в [Example](../../example/lib/main.dart)
Пример работы SDK доступен в [Example][example]

## Схема работы SDK
<details><img src="https://acdn.tinkoff.ru/static/pages/files/d3cd0230-03a1-47e6-bacf-dfdf9c8c1bea.png"/></details>

[documentation]: https://www.tinkoff.ru/kassa/develop/api/payments/
[acquiring]: https://www.tinkoff.ru/business/internet-acquiring/
[acquiring]: https://www.tinkoff.ru/business/internet-acquiring/
[example]: https://github.com/MadBrains/Tinkoff-Acquiring-SDK-Flutter/tree/main/example
4 changes: 3 additions & 1 deletion packages/tinkoff_acquiring/example/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
The [Example](../../../example/lib/main.dart) is in the corresponding folder
The [Example][example] is in the corresponding folder

[example]: https://github.com/MadBrains/Tinkoff-Acquiring-SDK-Flutter/tree/main/example
1 change: 1 addition & 0 deletions packages/tinkoff_acquiring/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ abstract class ApiMethods {
static const String addCard = 'AddCard';
static const String attachCard = 'AttachCard';
static const String check3DSVersion = 'Check3dsVersion';
static const String sendClosingReceipt = 'SendClosingReceipt';
}

abstract class Ignore {
Expand Down
2 changes: 2 additions & 0 deletions packages/tinkoff_acquiring/lib/src/core/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export './remove_customer/remove_customer_request.dart';
export './remove_customer/remove_customer_response.dart';
export './resend/resend_request.dart';
export './resend/resend_response.dart';
export './send_closing_receipt/send_closing_receipt_request.dart';
export './send_closing_receipt/send_closing_receipt_response.dart';
export './submit_3ds_authorization/submit_3ds_authorization_response.dart';
export './check_3ds_version/check_3ds_version_request.dart';
export './check_3ds_version/check_3ds_version_response.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import 'package:json_annotation/json_annotation.dart';

import '../../../constants.dart';
import '../../../utils/extensions.dart';
import '../base/acquiring_request.dart';
import '../common/receipt.dart';

part 'send_closing_receipt_request.g.dart';

/// Метод позволяет отправить закрывающий чек в кассу.
/// Условия работы метода:
/// 1. Закрывающий чек может быть отправлен если платежная сессия по первому чеку находится в статусе CONFIRMED.
/// 2. В платежной сессии был передан объект Receipt.
/// 3. В объекте Receipt был передан хотя бы один объект Receipt.Items.PaymentMethod = "full_prepayment" или "prepayment" или "advance"
///
/// [SendClosingReceiptRequest](https://www.tinkoff.ru/kassa/develop/api/payments/SendClosingReceipt-request/)
@JsonSerializable(includeIfNull: false)
class SendClosingReceiptRequest extends AcquiringRequest {
/// Создает экземпляр метода по отправке закрывающего чека в кассу
SendClosingReceiptRequest({
required this.paymentId,
required this.receipt,
String? signToken,
}) : super(signToken) {
validate();
}

/// Преобразование json в модель
factory SendClosingReceiptRequest.fromJson(Map<String, dynamic> json) =>
_$SendClosingReceiptRequestFromJson(json);

@override
String get apiMethod => ApiMethods.sendClosingReceipt;

@override
Map<String, dynamic> toJson() => _$SendClosingReceiptRequestToJson(this);

@override
Map<String, Object?> get equals => <String, Object?>{
...super.equals,
JsonKeys.paymentId: paymentId,
JsonKeys.receipt: receipt,
};

@override
SendClosingReceiptRequest copyWith({
int? paymentId,
Receipt? receipt,
}) {
return SendClosingReceiptRequest(
paymentId: paymentId ?? this.paymentId,
receipt: receipt ?? this.receipt,
);
}

@override
void validate() {
assert(paymentId.length <= 20);
receipt.validate();
}

/// Идентификатор платежа в системе банка
@JsonKey(name: JsonKeys.paymentId)
final int paymentId;

/// Данные чека
@JsonKey(name: JsonKeys.receipt)
final Receipt receipt;
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:json_annotation/json_annotation.dart';

import '../base/acquiring_response.dart';
import '../enums/status.dart';

part 'send_closing_receipt_response.g.dart';

/// Ответ от сервера на закрывающий чек в кассу
///
/// [SendClosingReceiptResponse](https://www.tinkoff.ru/kassa/develop/api/payments/SendClosingReceipt-response/)
@JsonSerializable()
class SendClosingReceiptResponse extends AcquiringResponse {
/// Создает экземпляр ответа от сервера на закрывающий чек в кассу
SendClosingReceiptResponse({
Status? status,
bool? success,
String? errorCode,
String? message,
String? details,
}) : super(
status: status,
success: success,
errorCode: errorCode,
message: message,
details: details,
);

/// Преобразование json в модель
factory SendClosingReceiptResponse.fromJson(Map<String, dynamic> json) =>
_$SendClosingReceiptResponseFromJson(json);

@override
Map<String, dynamic> toJson() => _$SendClosingReceiptResponseToJson(this);
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,25 @@ class NetworkClient {
_response =
response(<String, dynamic>{JsonKeys.cardInfo: json});
} else {
Exception('ApiMethod for list error');
throw Exception('ApiMethod for list error');
}
} else if (json is Map) {
_response = response(json as Map<String, dynamic>);
} else {
Exception('REST type error');
throw Exception('REST type error');
}

_config.logger.log(message: _response.toString(), name: 'Response');
_completer.complete(_response);
} else {
_completer.completeError(rawResponse);
throw http.ClientException(
rawResponse.reasonPhrase ?? '', rawResponse.request?.url);
}
})
.timeout(NetworkSettings.timeout)
.catchError((Object error) {
_config.logger.log(message: '', name: 'HTTP Error', error: error);
_config.logger
.log(message: '', name: 'HTTP Error', error: error.toString());
_completer.completeError(error);
});

Expand Down
Loading

0 comments on commit 8a0a7f4

Please sign in to comment.