phonegap/cordova PayPal intergration - php

I'm trying to integrate PayPal payments within my Phonegap app. I can't see a cross platform way to do it.
I can only see OS specific plugins which I can't use in Phonegap build. Is there a way of integrating it using the childbrowser? Also, I failed to find a plugin for Blackberry.
Note: I use Phonegap build, so I prefer a plugin-less solution.

what you can do is the in app browser to connect to a php driven page online and there do your paypal stuff.
http://docs.phonegap.com/en/2.3.0/cordova_inappbrowser_inappbrowser.md.html
function onDeviceReady() {
var ref = window.open('http://apache.org', '_blank', 'location=yes');
ref.addEventListener('loadstart', function() { alert('start: ' + event.url); });
ref.addEventListener('loadstop', function() { alert('stop: ' + event.url); });
ref.addEventListener('exit', function() { alert(event.type); });
}
Remember to white list the url that you will be using within phonegap else you will not to be able to make a connection.
On the php side write your own restfull api to handle the processing of the payments try to minimize the data sent to and from the api also try to use a secure connection if possible.
paypal examples can be found here:
https://www.x.com/developers/paypal/documentation-tools/paypal-code-samples
its a solution but i do advise to use plugins for every platform, with those you can better guarantee safety, less bugs and less development time.

Related

What is the way to add paypal payment without papypal's button in V2

I have the following cenario: On my page are different payment-options. First you choose the method, where by clicking on the paypal-button shout happens nothing. Only if you click then the order-and-pay-button it shout run the behavior of the paypal-button, with opening the paypal-dialog.
My first idea was to use the standard paypal-button and store it in an hidden field.
By clicking on my-paypal-button I load the paypal-script like this:
var wasLoaded = false;
function loadScript() {
if(wasLoaded) return;
wasLoaded = true;
var script = document.createElement('script');
script.type = 'text/javascript';
document.body.appendChild(script);
script.onload = function() {
paypal.Buttons({
// Set up the transaction
createOrder: function(data, actions) {
return actions.order.create({
purchase_units: [{
amount: {
value: '88.44'
}
}]
});
}, ...
load it to a hidden div.
}
script.src = 'https://www.paypal.com/sdk/js?client-id=SD&intent=capture&vault=false&commit=true';
}
by loading it to an hidden div.
By clicking on order-and-pay I make button.click() to execute the paypal-stuff.
But unfortunately the papypal-stuff is in a iframe, so I do not have access to it.
I could not find any hint in the paypal-specs. They wont always to use there button.
How can I achieve this approach?
Please refer to the below Server-Side API link which will help you achieve Server-side payment integration without PayPal Client's side button.
https://developer.paypal.com/docs/business/checkout/server-side-api-calls/
Feel free to let me know if you have any queries, also I am happy to share postman collections to play around with the APIs.
Speak to you soon!
Regards
Goutham AV
If you already have a button created, i woud just use a PHP generated Link:
If a user clicks on it, that user will be redirected to a PayPal Page -> buy on paypal -> get redirected to your page.
For that purpose i'd recommend PayPal PHP Api: PayPal PHP Api
Step 1: To get your libary working, download and install Paypal Api and start with that code:
<?php
// 1. Autoload the SDK Package. This will include all the files and classes to your autoloader
// Used for composer based installation
require __DIR__ . '/vendor/autoload.php';
// Use below for direct download installation
require __DIR__ . '/PayPal-PHP-SDK/autoload.php';
Step 2: You need to setup your PayPay ClientID and Secret:
// After Step 1
$apiContext = new \PayPal\Rest\ApiContext(
new \PayPal\Auth\OAuthTokenCredential(
'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS', // ClientID
'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL' // ClientSecret
)
);
Step 3: Use Code to generate a Link for your Button. You can use Code Samples from the Paypal Api Sample Pages here
I would recommend you the Code Sample: "PayPal Payments - similar to Express Checkout in Classic APIs"
I know there are maybe better ways to implement paypal buttons on a webpage, but this worked best for me.

Manage a server for notification system using PHP ratchets web sockets

Is it possible to achieve an online real-time notification system based (small scale)website which implements PHP ratchet websockets?
Locallly on my machine I start my PHP server using command prompt, but how could this be done for a hosted website?
As i will not be able start and maintain a server 24X7 for all remote clients, how would this actually work?(I dont have enough knowledge in this area)
Am i missing out on something?
Try the below code for notification feature:
<script>
if(typeof(EventSource) !== "undefined")
{
var source = new EventSource("demo_sse.php");
source.onmessage = function(event) {
notification(event.data);
};
}
</script>
And ofcourse you will need demo_sse.php which will be useful for fetching and storing data to the database.

Checkout.com payment integration in codeigniter

I am using checkout.com payment gateway. I want to integrate it to my website but in their developer area I am not able to find any suitable solution to integrate it with codeigniter. Below is the developer area of checkout.com
http://developers.checkout.com/
Any help in this regard will be very helpful. Thank you.
They are providing this code for implementation :
window.CKOConfig = {
debugMode: true,
publicKey: 'Your public key',
customerEmail: 'user#email.com',
ready: function (event) {
console.log("CheckoutKit.js is ready");
CheckoutKit.monitorForm('.card-form', CheckoutKit.CardFormModes.CARD_TOKENISATION);
},
apiError: function (event) {
// ...
}
But I am not able to understand that how I will call it with dynamic data and with my some conditions?
They won't give you a codeigniter integration, you can do it yourself with plain PHP though:
https://github.com/CKOTech/checkout-php-library
Did you even read their documentation?

Balancing PHP SDK and Cloud Code

Recently I decided to develop a web application about giving away accounts for a game (a meta-community) and chose Parse as my backend service. I was a newbie in network security. At first I implemented all the authentication as variable in client code and soon realized by myself that I could bypass them easily.
Then I moved every authentication step to Cloud Code, set up CLP and ACL. Now the client is only responsible for collecting data, putting them as parameters and calling Cloud Functions, and finally receiving the response and represent it. This was all achieved through pure JavaScript (both client and cloud code).
Now come the other part: PHP. My friend has always advised to try working with PHP instead. I also have my own dedicated server which supports PHP (and also an SQL database, but we are not going into that). Now I'm really teared up as I'm aware of some limitations with Cloud Code (like execution time limit).
So my question is, what can PHP and Cloud Code do that the other cannot, and should I be too worried about either one of them? Also, if you use Parse, what responsibility do you often give to PHP and Cloud Code?
EDIT: the code is not really relevant but I will try to provide some examples. This is a code segment in the client side:
$('#login').click(function () {
FB.login(function (response) {
if (response.status == 'connected') {
Parse.Cloud.run("facebookAuth", fbResponse.authResponse, {
success: function (response) {
console.log("User logged in through Facebook!");
Parse.User.become(response.sessionToken).then(function (loggedUser) {
// The current user is now set to user.
console.log("facebookAuth: Authentication completed.");
activityLog("User logged in through Facebook!");
}, function (error) {
// The token could not be validated.
console.log("The token could not be validated.");
activityLog("An error has occurred: " + error);
});
},
error: function (error) {
console.log(error);
activityLog("You need to be a group member to use the application!");
Parse.User.logOut();
}
});
}
});
});
This is the Cloud Functions for them:
Parse.Cloud.define("facebookAuth", function (fbAuthRes, response) {
// I implement the Facebook authentication here.
// If user is logged into Facebook (and is member of my group), then the user is logged in then:
response.success({user: user, sessionToken: user.getSessionToken()});
// The full code is too long.
}

Safe JavasScript that calls PHP script that calls external web service

I have a PHP page that needs to make a call to a external web service. This Web service call takes a bunch of sensitive data from a html form on the PHP page, e.g. SSN, and returns info related to that person.
The problem is that the web service call should be made as soon as the customer fills in the SSN field and the field loses focus, so the page cannot be reloaded in any way. I was thinking about using jQuery to make a call to the web service, but AJAX unfortunately requires that you are on the same domain as the requested resource. So I'm thinking about creating an local PHP page that makes the call to the web service and then use JQuery to call this new page.
Questions:
How do I use JQuery to call the local PHP script that makes the call to the web service?
Because the JQuery code will take sensitive data from a html form and send it to the PHP script, how can I encrypt the data?
To call your PHP file:
var url = "http://localhost/data.php";
var params = {
"SSN" : theSSN
};
$.get(url, params, function (){
// Do whatever you need here, once the data arrives.
});
To call the external webservice from PHP, I'd suggest using cURL.
To encrypt, I'd suggest using the HTTPS protocol instead of encrypting manually from JavaScript.
1) $.get("myscript.php", function(response) { alert(response) });
2) I wouldn't encrypt using jQuery, it would be slow and easy to decrypt. Enabling SSL on the server would be a better solution.
1: Ajax request example:
$.ajax(
{
type: "GET",
url: "http://yourdomain.com/yourpage.php",
success: function (msg) { //does something }
});
More details here
2: php XOR is a pretty good encryption algorithm, I use it myself for a project with sensitive data. you can find the function here.
Enjoy! :)
This probably won't help you in particular, but some webservices support something called JSONP, which adds a callback name to a normal JSON request.
However, chances are you will need to make some sort of local proxy, as not many JSONP services exist yet.
The way to go is enabling SSL on your domain, and doing the xmlHTTPRequest to the https of the remote service

Categories