I am using adaptive payments on my site, I can click buy on the item and complete the transaction which works fine. But after buying the item or clicking on cancel it doesnt redirect back to My site.
I tried to follow this example:
Adaptive Payments without modal box or popups?
But still cant get it working
Here is my current Javascript that im using:
$( document ).ready(function() {
$("form").submit(function (e) {
var className = $('form').attr('class');
var formname = this.name;
//alert(formname);
if(formname=="paypalform"){
//alert("testing");
var login = 'elgg-search elgg-search-header';
if(login) {
e.preventDefault();
//var agree = confirm('You are just about to ask the Post Pay Counter to prepare a PayPal payment on your behalf. Note that this will really take money from your account and into the selected writers ones\’. Please double check what you are doing, it is only your fault if something goes wrong.\n\nIf what you have done is fine, then you can go on with the payment. Just be patient during loading, please. In a couple of seconds the execute payment button will be clickable and you will be able to confirm this action. From this moment on you can not modify the payment selection, but if you reload the page before clicking the execute payment button, nothing will be done.');
//if (!agree)
// return false;
var className = $('form').attr('class');
//alert(className);
var data = {
action: 'the_php_page_that_will_handle_the_request.php',
payment_data: $(this).serialize()
};
$('#prepare_payment').attr("disabled", "true");
$("#prepare_payment_form :text").each(function() {
$(this).attr("disabled", "true");
});
var url_to_submit = $('#url_submit').text();
$.post(url_to_submit, data, function(response) {
if(response.indexOf("Error: ") != -1) {
$("#paypal_error").css("display", "block");
$("#paypal_error").html(response);
$('#prepare_payment').removeAttr("disabled");
jQuery("#prepare_payment_form :text").each(function() {
jQuery(this).removeAttr("disabled");
});
return false;
}
// enable for testing mode, to display pay key on ad view
//$('#txtHint').html( response );
//$('#txtHint').html( 'Redirecting to PayPal' );
//Store PayKey in the form action and enable execute payment button
$("#execute_payment_form").attr("action", "https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + response+"&expType=mini");
//document.getElementById('iframeid').src = url;
$('#execute_payment').removeAttr("disabled");
var url = "https://www.sandbox.paypal.com/webapps/adaptivepayment/flow/pay?paykey=" + response+"&expType=mini";
$(location).attr('href',url);
//document.getElementById('iframeid').src = url;
});
}
}
});
});
Related
I'm trying to integrate Google Pay at my page, as expected doing that first at Sandbox environment but I face a problem that when I click the Google Pay button it opens the live domain and asks me to enter a real card, although I setup up all related to Sandbox environment.
Here is the code following BT documentation.
var createGooglePaymentComponent = function(clientInstance){
var button = document.querySelector('#google-pay-button');
var paymentsClient = new google.payments.api.PaymentsClient({
environment: 'TEST' // Or 'PRODUCTION'
});
braintree.googlePayment.create({
client: clientInstance,
googlePayVersion: 2,
}, function (googlePaymentErr, googlePaymentInstance) {
paymentsClient.isReadyToPay({
apiVersion: 2,
apiVersionMinor: 0,
allowedPaymentMethods: googlePaymentInstance.createPaymentDataRequest().allowedPaymentMethods,
}).then(function(response) {
if (response.result) {
button.addEventListener('click', function (event) {
event.preventDefault();
var paymentDataRequest = googlePaymentInstance.createPaymentDataRequest({
transactionInfo: {
currencyCode: 'USD',
totalPriceStatus: 'FINAL',
totalPrice: '100.00',
}
});
var cardPaymentMethod = paymentDataRequest.allowedPaymentMethods[0];
cardPaymentMethod.parameters.billingAddressRequired = true;
paymentsClient.loadPaymentData(paymentDataRequest).then(function(paymentData) {
googlePaymentInstance.parseResponse(paymentData, function (err, result) {
if (err) {
// Handle parsing error
}
// Send result.nonce to your server
});
}).catch(function (err) {
});
});
}
}).catch(function (err) {
});
});
};
Here is a screenshot of what I get:
Any idea why does that happen?
Using Google Pay in the TEST environment will return a TEST payment credential which won't actually charge the payment method that you provide. It's understandable that you don't want to be using real payment details.
If you want to be able to choose from a list of predefined test cards, follow the instructions here: https://developers.google.com/pay/api/web/guides/resources/test-card-suite
In short, you will need to join the googlepay-test-mode-stub-data Google Group which will then display a list of test accounts when accessing the Google Pay payment sheet with that user.
I'm helping with a Squarespace site and it has a custom form added in code on a particular page. The form collects the payer's info, then can enter any amount in the "Total to charge" field, then it is supposed to display the 2.7% fee. However, I can ONLY get the fee to display if I refresh the page (chrome, safari, either one). Click here to see the page...let me know
here is a snippet of code:
<script>
$(document).ready(function () {
var $amount = $('input[name="amount_1"]');
var $fee = $("#fee");
var $total = $("#total");
var $amount_2 = $("input[name='amount_2']");
var processing_fee = .027;
var isCurrency = function (inval) {
var regex = /^[1-9]\d*(((,\d{3}){1})?(\.\d{0,2})?)$/;
if (regex.test(inval)) {
return true;
}
return false;
};
$amount.on('input propertychange', function () {
if (isCurrency($amount.val())) {
var fee = ($amount.val() * processing_fee).toFixed(2);
var total = (Number(fee) + Number($amount.val())).toFixed(2);
$fee.text('$' + fee);
$amount_2.val(fee);
$total.text('$' + total);
}
});
$amount.on('blur', function () {
$amount.val($amount.val().replace("$", ""));
$amount.val(Number($amount.val()).toFixed(2));
if (!isCurrency($amount.val())) {
$amount.val("");
}
});
$("#paymentform").validate({
submitHandler: function (form) {
form.submit();
}
});
});
</script>
When a custom script only runs on page refresh, the cause is likely to be Squarespace's AJAX loading:
Occasionally, Ajax may conflict with embedded custom code or anchor
links. Ajax can also interfere with site analytics, logging hits on
the first page only.
Disabling AJAX is often a simple solution:
You can disable Ajax in the Style Editor, with some exceptions:
Ajax can't be disabled in Skye, Foundry, or Tudor.
Ajax can't be disabled on the blog landing page for Farro and Haute. If you uncheck Enable Ajax Loading in these templates, they
will still use Ajax to load the Blog Page.
To enable or disable Ajax:
In the Home Menu, click Design, and then click Style Editor.
Scroll down to Site: Loading.
Check or uncheck Enable Ajax Loading.
If you do not want to disable AJAX, then see "Option 2" here for how to write your code so that it will work on initial page load and on AJAX page loads.
I cannot seem to make a test dialog appear. When I call payments.purchaseAync, I am always presented with a real Checkout dialog as opposed to a test dialog.
I've already added the test user to the Testers. Am I missing anything? Or is this feature not supported yet at this time?
Temporary code I'm using:
let supportedAPIs:any = FBInstant.getSupportedAPIs();
if(supportedAPIs.includes('payments.purchaseAsync'))
{
console.log('payments supported...');
FBInstant.payments.onReady(() => {
console.log('payments ready...');
FBInstant.payments.purchaseAsync({
productID: 'test_product',
developerPayload: 'foobar',
}).then(function (purchase) {
console.log(purchase);
});
});
}
else
{
console.log('payments not supported...');
}
I'm testing my web app login flow on the iOS8. I notice that on iOS8, the login dialogue pops up, but after logging in, it just stays there, showing a blank page.
The login works, because the page behind it shows the user information, but the popup just stays there, while it should close automatically. On iOS7 and iOS6 it does close. On desktop browsers it closes too.
I've tested some other random sites (for example brainfall.com) using FB.login(): same thing.
Does anyone have a fix for this?
Any help is much appreciated!
Check this:
fb_window_redirect
Override de window.open method. This allows you to know what windows are opened.
Then you can redirect the window opened by the FB SDK.
...
window._open = window.open; // saving original function
//Override the function
window.open = function(url,name,params) {
var new_window = window._open(url,name,params);
if (typeof onWindowOpen === "function") {
onWindowOpen(url, name, params, new_window);
}
return new_window;
};
...
var openedWindows = [];
var fbWindows = [];
function onWindowOpen(url, name, params, new_window) {
...
// Filter the facebook oauth request
if (url.contains('facebook.com')
&& url.contains('oauth')) {
fbWindows.push(new_window);
}
openedWindows.push(new_window);
}
...
//On fb login button pressed callback:
FB.login(function(response) {
//Try login
if(response.authResponse) {
//Login succesful
// Fb window redirect.
// see onWindowOpen
var fbwin = fbWindows[0];
var redirect_url = ''
fbwin.location = redirect_url;
}
},
{scope: 'email,publish_stream,user_birthday'});
...
i am just trying to implement facebook and twitter in my Webworks App and cannot get them work together.
I am using the FaceBook-OAuth-2 and the Twitter-OAuth-1 sample and i just put both stuff together and my problem is that only the first startOAuth() opens a window in the app to login the second doesn't so if i first clicked facebook it works after when i try twitter nothing happens.
https://github.com/blackberry/BB10-WebWorks-Samples
thanks
function setClickHandlers() {
console.log('set click handlers');
var fb = document.getElementById('facebookOn');
fb.addEventListener('click', function(e) {
// if the childWindow is already open, don't allow user to click the button
if(childWindow !== null) {
return false;
}
e.preventDefault();
toast('Contacting Facebook...');
setTimeout(function() {
startOAuth();
}, 500);
});
console.log('set twitter click handlers');
var tw = document.getElementById('twitterOn');
tw.addEventListener('click', function(e) {
// if the childWindow is already open, don't allow user to click the button
if(childWindow !== null) {
return false;
}
e.preventDefault();
toast('Fetching access token...');
setTimeout(function() {
twittergetAccessToken();
}, 500);
});
}
I would start by adding some debug code in your click handler to see if that's getting called when you click the button in the first place.
If it is, then I recommended you use Web Inspector (console) to see if there are any errors. If there are, they'll show up there.
Good reference for Web Inspector here - http://developer.blackberry.com/html5/documentation/web_inspector_overview_1553586_11.html
If the click handler is not being fired then perhaps you have the wrong element ID, or the setClickHandlers function is not being executed.