Skip to content

Commit

Permalink
Merge pull request #2 from igorpedrosogn/main
Browse files Browse the repository at this point in the history
Sample Payment Token Fixes
  • Loading branch information
iigorpedroso authored Aug 12, 2021
2 parents 51010b4 + e7e3bee commit 357dcf7
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 102 deletions.
3 changes: 2 additions & 1 deletion lib/credentials.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
dynamic CREDENTIALS = {
'client_id': '',
'client_secret': '',
'sandbox': false,
'account_id': '',
'sandbox': true,
'pix_cert': '',
'pix_private_key': ''
};
99 changes: 47 additions & 52 deletions lib/screens/default/charge/create_charge_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class _CreateChargeCardState extends State<CreateChargeCard> {
TextEditingController _nameController = new TextEditingController();
TextEditingController _cpfController = new TextEditingController();
TextEditingController _phoneController = new TextEditingController();
TextEditingController _paymentTokenController = new TextEditingController();
TextEditingController _streetController = new TextEditingController();
TextEditingController _numberController = new TextEditingController();
TextEditingController _neighborhoodController = new TextEditingController();
Expand Down Expand Up @@ -73,9 +72,6 @@ class _CreateChargeCardState extends State<CreateChargeCard> {
_form(_formBirth()),
_form(_formCpf()),
_form(_formPhone()),
_headerForm("Cartão",
"O campo abaixo é referente ao token de pagamento gerado para pagamentos com cartão."),
_form(_formPaymentToken()),
Container(height: 100)
],
)));
Expand Down Expand Up @@ -221,17 +217,6 @@ class _CreateChargeCardState extends State<CreateChargeCard> {
);
}

Widget _formPaymentToken() {
return FormDataField(
helperText: "Token de pagamento",
label: "PaymentToken*",
line: 1,
controller: _paymentTokenController,
textInputType: TextInputType.text,
validator: (value) => value.isEmpty ? "Campo Obrigatório!" : null,
);
}

Widget _formPhone() {
return FormDataField(
helperText: "Telefone do cliente (somente números)",
Expand Down Expand Up @@ -377,45 +362,55 @@ class _CreateChargeCardState extends State<CreateChargeCard> {

void _oneStep() {
setState(() => _loading = true);
Map<String, dynamic> body = {
"items": [
{
"name": _nameItemController.text,
"value": int.parse(_valueController.text),
"amount": int.parse(_amountController.text)
}
],
"payment": {
"credit_card": {
"installments": 1,
"payment_token": _paymentTokenController.text,
"billing_address": {
"street": _streetController.text,
"number": int.parse(_numberController.text),
"neighborhood": _neighborhoodController.text,
"zipcode": _zipcodeController.text,
"city": _cityController.text,
"state": _stateController.text
},
"customer": {
"name": _nameController.text,
"email": _emailController.text,
"cpf": _cpfController.text,
"birth": _birthController.text,
"phone_number": _phoneController.text
}
}
}

Map<String, Object> card = {
"brand": "",
"number": "",
"cvv": "",
"expiration_month": "",
"expiration_year": ""
};

gn.call("oneStep", body: body).then((value) {
setState(() => _loading = false);
_showMessage("Transação Criada!", Theme.of(context).accentColor,
MediaQuery.of(context).size.height);
}).catchError((error) {
setState(() => _loading = false);
_showMessage(
error.toString(), Colors.red, MediaQuery.of(context).size.height);
gn.call("paymentToken", body: card).then((value) {
Map<String, dynamic> body = {
"items": [
{
"name": _nameItemController.text,
"value": int.parse(_valueController.text),
"amount": int.parse(_amountController.text)
}
],
"payment": {
"credit_card": {
"installments": 1,
"payment_token": value['data']['payment_token'],
"billing_address": {
"street": _streetController.text,
"number": int.parse(_numberController.text),
"neighborhood": _neighborhoodController.text,
"zipcode": _zipcodeController.text,
"city": _cityController.text,
"state": _stateController.text
},
"customer": {
"name": _nameController.text,
"email": _emailController.text,
"cpf": _cpfController.text,
"birth": _birthController.text,
"phone_number": _phoneController.text
}
}
}
};
gn.call("oneStep", body: body).then((value) {
setState(() => _loading = false);
_showMessage("Transação Criada!", Theme.of(context).accentColor,
MediaQuery.of(context).size.height);
}).catchError((error) {
setState(() => _loading = false);
_showMessage(
error.toString(), Colors.red, MediaQuery.of(context).size.height);
});
});
}
}
95 changes: 49 additions & 46 deletions lib/screens/default/charge/pay_charge_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class _PayChargeCardState extends State<PayChargeCard> {
TextEditingController _nameController = new TextEditingController();
TextEditingController _cpfController = new TextEditingController();
TextEditingController _phoneController = new TextEditingController();
TextEditingController _paymentTokenController = new TextEditingController();
TextEditingController _streetController = new TextEditingController();
TextEditingController _numberController = new TextEditingController();
TextEditingController _neighborhoodController = new TextEditingController();
Expand Down Expand Up @@ -69,9 +68,6 @@ class _PayChargeCardState extends State<PayChargeCard> {
_form(_formBirth()),
_form(_formCpf()),
_form(_formPhone()),
_headerForm("Cartão",
"O campo abaixo é referente ao token de pagamento gerado para pagamentos com cartão."),
_form(_formPaymentToken()),
Container(height: 100)
],
)));
Expand Down Expand Up @@ -181,17 +177,6 @@ class _PayChargeCardState extends State<PayChargeCard> {
);
}

Widget _formPaymentToken() {
return FormDataField(
helperText: "Token de pagamento",
label: "PaymentToken*",
line: 1,
controller: _paymentTokenController,
textInputType: TextInputType.text,
validator: (value) => value.isEmpty ? "Campo Obrigatório!" : null,
);
}

Widget _formPhone() {
return FormDataField(
helperText: "Telefone do cliente (somente números)",
Expand Down Expand Up @@ -349,42 +334,60 @@ class _PayChargeCardState extends State<PayChargeCard> {
void _payCharge() {
setState(() => _loading = true);

Map<String, dynamic> params = {
"id": _idController.text,
Map<String, Object> card = {
"brand": "",
"number": "",
"cvv": "",
"expiration_month": "",
"expiration_year": ""
};

Map<String, dynamic> body = {
"payment": {
"credit_card": {
"installments": 1,
"payment_token": _paymentTokenController.text,
"billing_address": {
"street": _streetController.text,
"number": int.parse(_numberController.text),
"neighborhood": _neighborhoodController.text,
"zipcode": _zipcodeController.text,
"city": _cityController.text,
"state": _stateController.text
},
"customer": {
"name": _nameController.text,
"email": _emailController.text,
"cpf": _cpfController.text,
"birth": _birthController.text,
"phone_number": _phoneController.text
gn.call("paymentToken", body: card).then((value) {
Map<String, dynamic> params = {
"id": _idController.text,
};

Map<String, dynamic> body = {
"payment": {
"credit_card": {
"installments": 1,
"payment_token": value['data']['payment_token'],
"billing_address": {
"street": _streetController.text,
"number": int.parse(_numberController.text),
"neighborhood": _neighborhoodController.text,
"zipcode": _zipcodeController.text,
"city": _cityController.text,
"state": _stateController.text
},
"customer": {
"name": _nameController.text,
"email": _emailController.text,
"cpf": _cpfController.text,
"birth": _birthController.text,
"phone_number": _phoneController.text
}
}
}
}
};
};

gn.call("payCharge", params: params, body: body).then((value) {
setState(() => _loading = false);
_showMessage("Cartão Associado!", Theme.of(context).accentColor,
MediaQuery.of(context).size.height);
}).catchError((error) {
setState(() => _loading = false);
_showMessage(
error.toString(), Colors.red, MediaQuery.of(context).size.height);
gn.call("payCharge", params: params, body: body).then((value) {
setState(() => _loading = false);
_showMessage("Cartão Associado!", Theme
.of(context)
.accentColor,
MediaQuery
.of(context)
.size
.height);
}).catchError((error) {
setState(() => _loading = false);
_showMessage(
error.toString(), Colors.red, MediaQuery
.of(context)
.size
.height);
});
});
}
}
5 changes: 4 additions & 1 deletion lib/screens/default/others/installments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ class _InstallmentsState extends State<Installments> {
@override
void initState() {
super.initState();
gn = new Gerencianet(CREDENTIALS);
Map credentials = new Map.from(CREDENTIALS);
credentials.remove("pix_cert");
credentials.remove("pix_private_key");
gn = new Gerencianet(credentials);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/screens/pix/charge/pix_create_charge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class _PixCreateChargeState extends State<PixCreateCharge> {
return FormDataField(
helperText: "Texto a ser apresentado ao pagador ",
label: "Informação adicional",
hintText: "Ex: emailcliente@servidor.com.br",
hintText: "Ex: Cobrança produto X",
line: 3,
controller: _infoController,
textInputType: TextInputType.text,
Expand Down
57 changes: 57 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.0"
asn1lib:
dependency: transitive
description:
name: asn1lib
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
async:
dependency: transitive
description:
Expand Down Expand Up @@ -43,13 +57,34 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.3"
encrypt:
dependency: transitive
description:
name: encrypt
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.1"
fake_async:
dependency: transitive
description:
Expand All @@ -67,6 +102,20 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
gerencianet:
dependency: "direct main"
description:
name: gerencianet
url: "https://pub.dartlang.org"
source: hosted
version: "1.2.0"
js:
dependency: transitive
description:
name: js
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.3"
matcher:
dependency: transitive
description:
Expand All @@ -88,6 +137,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.8.0"
pointycastle:
dependency: transitive
description:
name: pointycastle
url: "https://pub.dartlang.org"
source: hosted
version: "3.2.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down Expand Up @@ -151,3 +207,4 @@ packages:
version: "2.1.0"
sdks:
dart: ">=2.12.0 <3.0.0"
flutter: ">=1.20.0"
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ environment:
dependencies:
flutter:
sdk: flutter
gerencianet: ^1.1.1
gerencianet: ^1.2.0

# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
Expand Down

0 comments on commit 357dcf7

Please sign in to comment.