how to track paypal transaction in google analytics - paypal

I want to track my conversions coming from Paypal checkout option.
I want to differentiate between conversions from normal checkout process & conversions from Paypal.

on the newest Paypal javascript API, this is how to log:
paypal.Button.render({
...
payment: function(data, actions) {
return new paypal.Promise(function (resolve, reject) {
// LOG BUTTON CLICKED
resolve();
}).then(function () {
return actions.payment.create({
..
});
});
},
onAuthorize: function(data, actions) {
return actions.payment.get().then(function(paymentDetails) {
...
return actions.payment.execute().then(function() {
// LOG FINISHED TRANSACTION
}})
},
// same for onerror, oncancel

Related

How to make the Stripe payment sheet for iOS in Flutter barrierDismissible: false?

I am using Stripe for iOS in my Flutter app and I want to disable the ability for the user to dismiss the payment sheet by tapping outside of it. Currently, when the user taps outside of the payment sheet, I am receiving an error from Stripe. I know that the barrierDismissible option is not available for the presentPaymentSheet() method, but I am wondering if there is some other way to enable this behavior for the payment sheet.
Here is my code demonstrating how I am currently displaying the payment sheet:
Future<void> makePayment(String amount, String currency) async {
try {
paymentIntentData = await createPaymentIntent(amount, currency);
if (paymentIntentData != null) {
await Stripe.instance.initPaymentSheet(
paymentSheetParameters: SetupPaymentSheetParameters(
billingDetails: BillingDetails(
name: _nameController.text,
phone: _phoneController.text,
email: _emailController.text,
),
allowsDelayedPaymentMethods: false,
customerEphemeralKeySecret: paymentIntentData!['ephemeralkey'],
paymentIntentClientSecret: paymentIntentData!['client_secret'],
customerId: paymentIntentData!['customer'],
style: ThemeMode.dark,
merchantDisplayName: 'company',
),
);
}
//Payment Sheet
///now finally display payment sheet
displayPaymentSheet();
//displayPaymentSheet();
} catch (e, s) {
print('ERROR exception:$e$s');
}
}
displayPaymentSheet() async {
try {
await Stripe.instance.presentPaymentSheet().then((value) async {
// Code to handle the result of the payment
}).onError((error, stackTrace) {
print('Error is:--->$error $stackTrace');
});
} on StripeException catch (e) {
print('StripeException Error is:---> $e');
showDialog(
context: context,
builder: (_) => const AlertDialog(
content: Text("Cancelled "),
));
} catch (e) {
print('$e');
}
}
Is there any way to make the payment sheet barrierDismissible: false using the presentPaymentSheet() method or some other method in Stripe for iOS in Flutter?
The flutter_stripe package does provide native integration of the Stripe payment sheet within your Flutter app, it is not a flutter's bottom sheet widget, so you can't actually control and make such as change like this to the presentPaymentSheet() bottom sheet.
Also other Stripe's CardField() and CardFormField() are technically native platform-specific views integrated inside the flutter app.

is there a way to get response from a request sent from browser in flutter app

I have a flutter app where users are required to pay to see some content the payment is done with pay pal and after the payment is done from the browser/web view then a request is sent to the backend and the backend will send the token to the webpage so I want to access that token in the app to check if the payment was successful to open the payment page I use
_launchURLApp() async {
if (await canLaunchUrl(Uri.parse(url))) {
await launchUrl(Uri.parse(url));
} else {
throw 'Could not launch $url';
}
}
onTap: () {
ApiClient.payWithPayPal().then((response) => {
setState(() {
url = response;
}),
_launchURLApp()
});
}

next-auth pass the data in signin callback

I am making login process with next-auth.
I am using Google as OAuth Provider.
// pages/api/auth/[...nextauth].ts
export default async function auth(req: any, res: any) {
return await NextAuth(req, res, {
//...
callbacks: {
async signIn({ user, account }) {
// console.log(user); // data exists.
const isUser = await apiForIsUser();
if(isUser) return true; // redirect to root page.
return '/sign-up'; // redriect to sign-up page.
}
}
});
}
above code works, but I can not touch data from OAuthProvider in sign-up page.
How can I pass the data from 'OAuthProvidertosign-up` page?

Paypal javascript sdk onClick not prevent popup showing

I follow this documentation to integrate paypal javascript sdk. I want validate user input after paypal button click and prevent paypal window display if validation fail.
paypal.Buttons({
onClick: function(data, actions) {
console.log('click >>>>>')
return actions.reject();
// return false;
},
createOrder: function(data, actions) {
return fetch('/checkout/submit/paypal/create_order', {
method: 'post',
headers: {
'content-type': 'application/json'
},
body: JSON.stringify(_this.getSubmitData())
}).then(function(res) {
return res.json();
}).then(function(detial) {
return detial.orderId
});
},
onApprove: function(data, actions) {
// data > { billingToken, facilitatorAccessToken, orderID, payerID, paymentID }
return fetch('/checkout/submit/paypal/capture_order?orderId=' + data.orderID, {
method: 'post',
headers: {
'content-type': 'application/json'
},
}).then(function(res) {
return res.json();
}).then(function(details) {
console.log(details);
})
}
}).render('#paypal-button-container');
When i click the paypal button, console show my message click >>>>> and a new window display and disappear immeditely.
I don't think it should show a new window.
I don't think it should show a new window.
Nonetheless, that's how it works if you reject from onClick.
To prevent the popup from opening, you need to disable the buttons in onInit and add a listener for re-enabling them when appropriate, as documented in the link in your question.

wait for complete page load does not work as expected in Protractor

I am writing a test for login into non-angular application.
describe('login Test for App', function () {
beforeEach(function () {
browser.ignoreSynchronization=true;
browser.get(loginPageURL,2000);
});
it('It should Login a User', function () {
element(by.id('username')).sendKeys(constants.userName);
element(by.id('password')).sendKeys(constants.password);
element(by.id('Login')).click().then(function () {
// Waiting to open modal
browser.wait(function () {
return browser.getCurrentUrl().then(function (url) {
return url==dashboardUrl;
});
});
});
});
});
After login, I want to check currentUrl. But After login button click, It waits till dashboard url appeared.
But when after loginbutton click, It go to diffrent url, Then it also wait for dashboard url infinite.
I want to check current url after login event, if it is not dashboard url, then it should fail, and do not run next test suite cases, because login Test is failed.
Like-
When clickOn login button.
Wait for complete page load.
2.Then check current url, If it is not dashboard url, then test should failed, and not proceed for any test cases.
It is not best practice to wait for the pages url to load in order to know if the page is loaded, because there could be redirects or other things.
It is best practice to wait for a specific element on the next page(after log-in). Here is your code refactored to use a custom wait() function that will wait for an element to appear before continuing to retrieve the current url:
describe('login Test for App', function () {
browser.ignoreSynchronization = true;
it('should load the log-in page', function(done) {
browser.driver.get(loginPageURL).then(function() {
browser.driver.sleep(2000);
wait('#username', 10000);
done();
});
});
it('It should Login a User', function (done) {
element(by.id('username')).sendKeys(constants.userName);
element(by.id('password')).sendKeys(constants.password);
element(by.id('Login')).click().then(function () {
// Waiting to open modal
wait('#element_on_the_next_page', 10000);
browser.getCurrentUrl().then(function (url) {
// do anything with the url
done();
});
});
});
function wait(selector, timeout) {
browser.driver.wait(function() {
return browser.driver.isElementPresent(by.css(selector)).then(function(present) {
return present;
});
}, timeout);
browser.driver.wait(function() {
return browser.driver.findElement(by.css(selector)).isDisplayed().then(function(displayed) {
return displayed;
});
}, timeout).then(function() {
return;
});
}
});
Hope this helps!