Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

preference info #11

Closed
luisNezi opened this issue Aug 1, 2019 · 1 comment
Closed

preference info #11

luisNezi opened this issue Aug 1, 2019 · 1 comment

Comments

@luisNezi
Copy link

luisNezi commented Aug 1, 2019

hello!
I'm having some problems trying to implement the funcionality "getpreference"
It lead's me to an error message.

the code is:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mood/classes.dart';
import 'package:mood/style/components/textFieldFormularios.dart';
import 'package:mood/style/fonts.dart';
import 'package:flutter_google_pay/flutter_google_pay.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';

class CartaoPage extends StatefulWidget {
CartaoPage(this.mediaHeight, this.mediaWidth, {Key key})
: super(key: key);
final double mediaHeight;
final double mediaWidth;

@OverRide
CartaoPageState createState() => new CartaoPageState();
}

class CartaoPageState extends State {
@OverRide
void initState() {
super.initState();
}

@OverRide
Widget build(BuildContext context) {
MercadoPago mercadoInstance = new MercadoPago();
_makeCustomPayment() async {
var environment = 'rest'; // or 'production'

  if (!(await FlutterGooglePay.isAvailable(environment))) {
    print('Google pay not available');
  } else {
    ///docs https://developers.google.com/pay/api/android/guides/tutorial
    PaymentBuilder pb = PaymentBuilder()
      ..addGateway( "PAYMENT_GATEWAY","3359798608018742195")
      ..addTransactionInfo("1.0", "USD")
      ..addAllowedCardAuthMethods(["PAN_ONLY", "CRYPTOGRAM_3DS"])
      ..addAllowedCardNetworks(
          ["AMEX", "DISCOVER", "JCB", "MASTERCARD", "VISA"]
      )
      ..addBillingAddressRequired(true)
      ..addPhoneNumberRequired(true)
      ..addShippingAddressRequired(true)
      ..addShippingSupportedCountries(["US", "GB","BR"])
      ..addMerchantInfo("Example");

    Result result = await FlutterGooglePay.makeCustomPayment(pb.build()).catchError((error) {
      print(error);
    });
    if (result.status == ResultStatus.SUCCESS) {
      print('Success');
    } else if (result.error != null) {
      print(result.error);
    }
  }
}

Future<Map<String, dynamic>> index() async {
  var payer = {
    'email': 'abdul@live.com'
  };
  var preference = {
    "items": [
      {
        "title": "Test",
        "quantity": 1,
        "currency_id": "BRL",
        "unit_price": 10.4,
        "payer":payer
      }
    ],
  };

  var result = await mercadoInstance.mp.createPreference(preference);

  return result;
}

_launchURL(String url) async {
  if (await canLaunch(url)) {
    await launch(url);
  } else {
    throw 'Could not launch $url';
  }
}

return Scaffold(
  backgroundColor: Color(0xff5c31b8),
  appBar: AppBar(
    backgroundColor: Color(0xff5c31b8),
    elevation: 0,
    actions: <Widget>[],
  ),
  body: SingleChildScrollView(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.center,
      children: <Widget>[
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            ConstrainedBox(
              constraints: BoxConstraints(
                maxWidth: widget.mediaWidth * 0.9,
              ),
              child: TextFieldFormulario(
                context,
                textInputAction: TextInputAction.next,
                style: AntipastoTextStyle(
                    color: Colors.white, fontSize: 20.0),
                labelText: "Numero do Cartão ",
                labelStyle: AntipastoTextStyle(
                    color: Colors.white, fontSize: 20.0),
              ),
            ),
          ],
        ),
        FlatButton(
          child: Text('Google Pay'),
          onPressed: ()async{
            _makeCustomPayment();
          },
        ),
        FlatButton(
          child: Text('Mercado Pago'),
          onPressed: ()async{
            var payment = await index();
            print(payment);
            var url = payment['response']["sandbox_init_point"];
            String iDe = payment['response']["id"];
            var result = await mercadoInstance.mp.getPreference(iDe);
            print(result);
          },
        )
      ],
    ),
  )
);

}
}

it gives me the error message:

Exception has occurred.
NoSuchMethodError (NoSuchMethodError: The getter 'keys' was called on null.
Receiver: null
Tried calling: keys)

Thanks

@hostelix
Copy link
Member

Fix #14

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants