molpay_facebook_seamless.js - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: molpay_facebook_seamless.js fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of molpay_facebook_seamless.js.php

  1. $(function() {
  2.     $.ajaxSetup({
  3.         cache: true
  4.     }); //Enable catching - jQuery will timestamp by default.
  5.     //$.getScript('//connect.facebook.net/en_US/sdk/debug.js', function(){
  6.     $.getScript('//connect.facebook.net/en_US/all.js', function() {
  7.  
  8.         FB.init({
  9.             appId: '(Your FB AppID)',
  10.         });
  11.  
  12.         FB.getLoginStatus(function(response) {
  13.             if (response.status === 'connected') {
  14.                 console.log('Logged in.');
  15.                 FB.api('/me', function(response) {
  16.                     //
  17.  
  18.                     /*BELOW: 2 lines of code that set the bill_name and bill_email automatically. The setting is
  19.                     ** on data attributes. Then the rest is done as in usual seamless integration.
  20.                     ##USER: have to link to MOLPay facebook .js after linking to jQuery but before linking to
  21.                     ## MOLPay seamless .js.
  22.                     */
  23.  
  24.                     $('#molpay_btn').html("<button type=\"button\" id=\"myPay\" class=\"btn btn-primary btn-lg\" data-toggle=\"molpayseamless\" data-mpsmerchantid=\"molpaymerchant\" data-mpschannel=\"maybank2u\" data-mpsamount=\"1.20\" data-mpsorderid=\"TEST1139669863\" data-mpsbill_name=\"\" >Pay by Maybank2u</button>");
  25.  
  26.                     var var_mpsbill_name = response.name;
  27.                     var var_mpsbill_email = response.email;
  28.                     if ($("[data-toggle=\"molpayseamless\"]")) {
  29.                         $("[data-toggle=\"molpayseamless\"]").attr('data-mpsbill_name', var_mpsbill_name)
  30.                     } else {
  31.                         $("[data-toggle=molpayseamless]").attr('data-mpsbill_name', var_mpsbill_name);
  32.                     } //End of if()
  33.                     if ($("[data-toggle=\"molpayseamless\"]")) {
  34.                         $("[data-toggle=\"molpayseamless\"]").attr('data-mpsbill_email', var_mpsbill_email);
  35.                     } else {
  36.                         $("[data-toggle=molpayseamless]").attr('data-mpsbill_email', var_mpsbill_email);
  37.                     } //End of if()
  38.                     if ($("[data-toggle=\"molpayseamless\"]")) {
  39.                         $("[data-toggle=\"molpayseamless\"]").attr('data-mpsreturnurl', window.location.href);
  40.                     } else {
  41.                         $("[data-toggle=molpayseamless]").attr('data-mpsreturnurl', window.location.href);
  42.                     } //End of if()
  43.  
  44.                     alert("BILL_NAME: " + $("[data-toggle=molpayseamless]").attr('data-mpsbill_name') + "\n\nBILL_EMAIL: " + $("[data-toggle=molpayseamless]").attr('data-mpsbill_email') + "\n\nBILL_AMOUNT: " + $("[data-toggle=molpayseamless]").attr('data-mpsamount') + "\n\nMERCHANTID: " + $("[data-toggle=molpayseamless]").attr('data-mpsmerchantid'));
  45.                 });
  46.                 console.log('Logged in=> DONE');
  47.             } else {
  48.                 //
  49.                 console.log('NOT LOGGED IN');
  50.                 FB.login(function(response) {
  51.                     //
  52.                     //alert("Login response....");
  53.                     console.log('LOGIN RESPONSE....');
  54.  
  55.                     window.location = window.location.href;
  56.  
  57.                     console.log('LOGIN RESPONSE....=> DONE');
  58.                 }, {
  59.                     scope: 'public_profile,email'
  60.                 });
  61.                 //alert("else");
  62.                 console.log('NOT Logged in=> DONE');
  63.             } //End of if()
  64.         });
  65.     });
  66. });
  67.  
File Description
  • molpay_facebook_seamless.js
  • PHP Code
  • 06 Mar-2024
  • 3.36 Kb
You can Share it: