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'],
]
);
Related
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,
);
}
I'm new to flutter technology and trying to learn to work with API, the confusion I'm having is that when I look down and study the stripe documentation for payment or any other API, it is accepting everything as a parameter but in my code, I'm passing the body that is required by stripe as a parameter and it works fine, so I am confused why does it work fine while the stripe API wants the data as parameters
Below is the code I've written so please anyone help me understand this,
is this because of the content type I am providing or what?
Please Clarify me,
Thanks
Map<String, dynamic> body = {
'amount': amountInUSDCents.toString(),
'currency': currency,
'payment_method_types[]': 'card',
'receipt_email': widget.email,
};
Uri url = Uri.parse('https://api.stripe.com/v1/payment_intents');
var response = await http.post(url, headers: {
'Authorization':
'Bearer secret key here',
'Content-Type': 'application/x-www-form-urlencoded'
});
I am trying to integrate paypal api with PHP compared to the old button form that I have used to date on my sites. But there is one thing that is not clear to me, is it more correct to integrate paypal with client_id and secret or through the codes provided in the account panel (api username, api password and signature)? I followed the REST API integration guide (version 2) but they require client_id and secret. So what is the data in the account panel for? Anyone can clarify my ideas? Thank you
The API username, password, and signature is used by the classic NVP/SOAP APIs, which are much older than the REST API. They exist only for backwards compatibility with old shopping cart software and such integrations.
The v2/checkout/orders API should be used for current PayPal Checkout integrations. Pair two routes on your server (one for create order, one for capture order) that return/output only JSON data (never any HTML or text) with this JS approval flow.
I would go with JS SDK inline integration - requires client-id only and is more flexible than checkout buttons. Also creates nice user experience as if staying on the page (no redirects to 3rd party site). See all demos here.
paypal.Buttons({
createOrder: function(data, actions) {
return actions.order.create({
// note: custom_id (127 chars) will be passed later back in capture
purchase_units: [{
amount: {
value: amtDue.toFixed(2),
currency: 'EUR'
},
description : description,
custom_id : '<?= $encryptedPaymentData ?>'
}]
});
},
onApprove: function(data, actions) {
$("#global-spinner").show();
// set custom capture handler
return actions.order.capture().then(function(details) {
$.ajax({
type: "POST",
url: "/paypal/success",
data: ({
details : details,
ad : amtDue,
desc : description,
_token : '<?= $csrf ?>'
}),
success: function(resp) {
$("#global-spinner").hide();
window.showThankYou(); // some "thank you" function
},
error: function() {
$("#global-spinner").hide();
alert("Connection error.");
}
});
});
},
onError: function (err) {
// some custom function - send error data to server logger
window.handlePaypalError(err, description, amtDue);
}
}).render('#paypal-button-container');
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.
I've integrated PayPal Smart Buttons in my website, both createOrder and Capture are processed on the server side, when a payment has been completed the transation is available on business sandbox account and the webhook event is registered in Webhooks Events page.
The webhook POST url is subscribed in dashboard to all event and to test it in localhost i use webhookrelay.
The issue is that i get the webhook called only when the event comes from the Webhook Simulator and not from an actual payment from Smart Button.
So my server receives webhook calls only from the simulator and is NOT triggered from a Smart Button payment.
I'm in sandbox mode and all payments and Smart Buttons are in sandbox mode.
Here is my Smart Button code:
paypal
.Buttons({
style: {
shape: "rect",
color: "gold",
layout: "horizontal",
label: "paypal",
tagline: false,
height: 52,
},
createOrder: async function () {
const res = await fetch(
"https://www.example.it/payment/paypal/order/create/" + orderID,
{
method: "post",
headers: {
"content-type": "application/json",
},
credentials: "include",
}
);
const data = await res.json();
return data.id;
},
onApprove: async function (data) {
const res = await fetch(
"https://www.example.it/payment/paypal/" +
data.orderID +
"/capture/",
{
method: "post",
headers: {
"content-type": "application/json",
},
credentials: "include",
}
);
const details = await res.json();
if (localStorage.STBOrder) {
localStorage.removeItem("STBOrder");
}
$("#modalPayments").modal("hide");
$("#modalSuccess").modal("show");
},
onCancel: function (data) {},
})
.render("#paypal-button-container");
Since you are capturing on the server side, there is no real motivation to use webhooks. The response of your API call to do the capture is already authoritative; a webhook provides no useful additional information
If you insist on implementing webhooks for some reason, you need to register a listener for the events you want to receive. There is an API for managing webhook registrations: https://developer.paypal.com/docs/api/webhooks/v1/#webhooks_post , or you can try the steps in this guide https://developer.paypal.com/docs/api-basics/notifications/webhooks/rest/#subscribe-to-events
Again, implementing asynchronous webhooks is completely unnecessary when you have already implemented a synchronous capture API call on your server.