Flutter Integrate Apple pay response to stripe - flutter

Unhandled Exception: StripeException(error: LocalizedErrorMessage(code: FailureCode.Failed, localizedMessage: There was an unexpected error -- try again in a few seconds, message: No such payment_intent: 'pi_3M9vFfDn3WtZLRhzO5kP10SM', stripeErrorCode: resource_missing, declineCode: null, type: invalid_request_error))
I hit apple pay then after payment , reverted to stripe payment intent and then I get client secret from response . I revert that response to Stripe for payment verification and I got response as No such payment_intent or getting payment method reuired
#ᴅ ᴇ ʙ ᴊ ᴇᴇ ᴛ and #orakaro here is what I done
Future<void> onApplePayResult(paymentResult) async {
debugPrint("paymentResult.toString() is ${paymentResult.toString()}");
var data = jsonDecode(paymentResult['token']);
debugPrint("data is $data");
String transactionId = data['data'];
var response = await PaymentService().makePayment(
context: context,
amount: 100
,
);
String clientSecret = response['client_secret'].toString();
final params = PaymentMethodParams.cardFromToken(
paymentMethodData: PaymentMethodDataCardFromToken(
token: token,
));
await Stripe.instance.confirmPayment(
"clientSecret",
params,
);
}

Related

Adding extra information to Stripe payment intent

I have implemented Stripe in my Flutter app, but I would like to add some information to the payment done in order to recognize the payment inside the payments list inside the Stripe dashboard panel.
This is the response from Stripe when generating a payment:
// 1. Create a payment intent on the server
final response = await http.post(
Uri.parse(
'https://...stripePaymentIntentRequest'),
body: {
'email': email,
'amount': amount.toString(),
'description': widget.codigo_pedido ,
});
final jsonResponse = jsonDecode(response.body);
print("respuests stripe: ${jsonResponse.toString()}");
respuests stripe: {paymentIntent: pi_3M6dBTCcyi0G23rG0FoA7fEl_secret_h6dewQiWveMe5HsPg5MxCduTB, ephemeralKey: ek_test_YWNjdF8xR3NQRm5DY3lpMEcyM3JHLHFiV3ZQRkpBM3VHNHNFOFM3RHJvemxiYlpyaTRSazA_00HIJiGkLl, customer: cus_MqJLygEutMbF4X, success: true}
Is there a way to add some extra information inside the payment intent?
To store additional information on the Payment Intent object, you can add a metadata. Metadata is a key-value pairs that can be attached to an object. To learn more, you review this document.
Your server side code should look something like this:
$stripe->paymentIntents->create(
[
'amount' => 1099,
'currency' => 'usd',
'metadata' => ['order_id' => '6735'],
]
);

Ethereum eth_sendRawTransaction not getting success after sign transactions from walletcore

I am trying to sign a simple transaction in the Ropsten testnet using Trustwallet WalletCore flutter library and then broadcast transactions raw data to ethereum ropsten testnet network using web3dart, Here after calling eth_sendRawTransaction getting multiple errors as "got code -32000 with msg exceeds block gas limit", got code -32000 with msg "insufficient funds for gas * price + value"
Here is my code:
final signingInput = Ethereum.SigningInput(
chainId: Uint8List.fromList([0x03]),
nonce: Uint8List.fromList([0x82]),
gasLimit: Uint8List.fromList("21000".codeUnits),
gasPrice: "${etherAmount.getInWei}".codeUnits,
transaction: Ethereum.Transaction(
transfer: Ethereum.Transaction_Transfer(
amount: utf8.encode("1000000000"),
),
),
toAddress: "0xEF5b5b802144a9.......eB62aDc973B5B",
privateKey: secretPrivateKeyEth.data(),
);
final sign = AnySigner.sign(signingInput.writeToBuffer(), coin);
final signingOutput = Ethereum.SigningOutput.fromBuffer(sign);
print(hex.encode(signingOutput.encoded));
var httpClient = http.Client();
var web3 = await Web3Client(
"https://ropsten.infura.io/v3/06a5e776d.......b82d7c51d",
httpClient);
var result = await web3
.sendRawTransaction(Uint8List.fromList(signingOutput.encoded));
print("SendRawTransaction Result : ${result.toString()}");

Flutter google sign in serverAuthCode

I'm using this flutter plugin google_sign_in 5.2.1
works good I get the response
{displayName: Mario Mc, email: myemail#gmail.com, id: 117816213074325689769, photoUrl: https://lh3.googleusercontent.com/a-/AOh14GgyaPy7ik693hjyIBmtW5IRXUdCXluaeI=s96-c, serverAuthCode: 4/0AX4XfWiqJ1DMfPaDbgf6gOFVMCfgMicyPqGk25bxjKfA4wq7bJCCu-TWRB8c3rAz_g}
My question is: what is serverAuthCode?
And what's id: 117816213074325689769 used for
And after I send that serverAuthCode to the server, how do I verify that code is legit by calling google servers(as you know any person can send a fake serverAuthCode, so we need to verify it before saving it or do something with it)
I want to use PHP in the server side
thanks
What you can do is use this to get the accessToken then send it to the server
// sign In With Google
_googleSignIn.signIn().then((userData) {
userData.authentication.then((googleKey) {
setState(() {
// Retrieve the email from Google auth
googleEmail = userData.email;
googleId = userData.id;
googlePhotoUrl = userData.photoUrl;
googleServerAuthCode = userData.serverAuthCode;
googleAccessToken = googleKey.accessToken;
googleIdToken = googleKey.idToken;
});
print("googleAccessToken");
print(googleAccessToken);
// call your login function if no errors
checkInternetAndLoginWithGoogle();
}).catchError((err) {
print('inner error');
});
}).catchError((err) {
print('error occurred');
print(err);
});
in the server side, you can verify that access token by calling
https://www.googleapis.com/oauth2/v3/tokeninfo?access_token=<access token>
you will get an answer if that token is valid or expired
Also, you can call this to get user info such as name, email, photo etc.
https://www.googleapis.com/oauth2/v3/userinfo?access_token=<access token>

Stripe does not show payment sheet

I do receive the client secret and all my test payments are shown on stripe dashboard. However when calling present payment it gives me the error 'No payment sheet has been initialized yet'.
// calling func on cloud functions
// create payment intent
final url = Uri.parse(
'https://us-central1-wpbakery-52166.cloudfunctions.net/stripePayment');
final response =
await http.get(url, headers: {'Content-Type': 'application/json'});
_paymentIntent = json.decode(response.body);
print(_paymentIntent);
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
paymentIntentClientSecret: _paymentIntent['paymentIntent'],
applePay: true,
style: ThemeMode.dark,
));
await Stripe.instance.presentPaymentSheet();
}```
I assume you're using the flutter_stripe library?
If so, then you need to also be passing in merchantCountryCode in SetupPaymentSheetParameters since the docs mention that it's required when Apple Pay is enabled [1].
You should also make sure you set Stripe.merchantIdentifier before calling initPaymentSheet.

Payfast Api integration to Flutter App Http request Errors

I am building an app with Payfast payment gateway. The gateways documentaion only covers php side but I want to make it by requesting https. Trying to resolve the situation but don't understand where I am wrong.
Trying to make simple form integration on this site payfast_developers_docs
I got 404 and 500 error. Can not reach checkout form. Thanks for now.
Below my source code;
DateTime ax= DateTime.now();
print(ax);
String a = "amount=100.00&Content-Type=application/json&item_name=#000001&merchant_id=10000100&merchant_id=10000100&merchant_key=46f0cd694581a&timestamp=$ax&version=v1";
md5.convert(utf8.encode(a)).toString();
//String pkistring = v1hashing(requeststr);
HttpClient httpClient = new HttpClient();
HttpClientRequest request = await httpClient.postUrl(Uri.https( "sandbox.payfast.co.za", "/eng/process​"));
request.headers.set('Content-Type' , 'application/json');
request.headers.set('merchant-id' , '10000100');
request.headers.set('version' , 'v1');
request.headers.set('timestamp' , ax);
request.headers.set('signature' , md5.convert(utf8.encode(a)).toString());
//headers
//request.headers.set('Accept' , 'application/json');
Map body = { 'merchant_id' : '10000100',
'merchant_key' : '46f0cd694581a',
'amount' : '100.00',
'item_name' : '#000001',
'signature': '${md5.convert(utf8.encode(a)).toString()}'} ;
//body
request.add(utf8.encode(json.encode(body)));
//response cevap
HttpClientResponse response = await request.close();
print(response.statusCode); // baglanti yapildi mi yapilmadi mi 200 ise yapildi
String reply = await response.transform(utf8.decoder).join();
//Map responseMap = json.decode(reply);
httpClient.close();
print("payfast ici odeme");
print(reply);
Navigator.push(context, MaterialPageRoute(builder: (context) => new a3dsecure(reply)));