Jump to content

[UPDATE] Fetch to page in modules (PayPal Commercial Platform Serve-side)


Marco Ro
 Share

Recommended Posts

Hello all,

is it possible to fetch to a php page inside a Modules folder?

I need to perform a server-side operation, I have to fetch a json to this php page and do a crul to generate an ID on the external platform (and then pass this ID into another API call).

But I get error 403 when I try to fetch data to the file inside modules.

What I can do?
thank you

Link to comment
Share on other sites

Hi @Marco Ro. I have read this several times and I am not sure I understand it all. 

3 hours ago, Marco Ro said:

is it possible to fetch to a php page inside a Modules folder?

  1. Could you please explain what you mean by a php page? Do you mean a PHP file?
  2. Secondly, what module is this? Is this a custom module you are developing, e.g., /site/MyModule/.
  3. Is it perhaps a Process Module? If so, by page, do you mean executeSomePage() in your custom Process Module?
3 hours ago, Marco Ro said:

I need to perform a server-side operation, I have to fetch a json to this php page and do a crul to generate an ID on the external platform (and then pass this ID into another API call).

  1. Are you talking about two servers talking to each other?
  2. How are you fetching the JSON? Are you accessing some API endpoint?
  3. Are you fetching the JSON using CURL?
  4. By 'another API call', do you mean a different (third) server?
3 hours ago, Marco Ro said:

But I get error 403 when I try to fetch data to the file inside modules.

OK, this means whatever is trying to access your file inside your modules folder is forbidden to do so, which is expected, but dependent on where the call is coming from. 

I think if you could provide some code, illustration or clarifications to the above questions, we would be better placed to assist.

  • Like 2
Link to comment
Share on other sites

Hi @kongondo, thank you for your help. You're right, let me explain:

I'm currently developing a PayPal payment module. After a call with one of their sales representatives, he told me that PayPal is drastically lowering the fees for card transactions outside of PayPal account, and that it will implement various implementations in the future, such as recurring payments, crypto wallets, etc.
All this will be possible with the use of PayPal Commercial Platform Serve-side.

So I'm getting to work on creating the module.

I use Padloper 0.0.2, I was able to render correctly the form inside the Confirmation page. After that I have to send a CRUL call to the PayPal server to generate an ID order, that needed to make the payment (with another call). So, from the Confirmation page I rendere the script, the forms and create a JSON with all information about the transaction, this must been send to a page that executes a CRUL call to PayPal's Server. Being serve side, I can't do it from the Confirmation page because the page has already been rendered and also because the call starts when the payment button is clicked. So, I have a second page inside the module that handles this call and returns the PayPal order ID. But I can't make this call. I'm stack here.

Kindly, the technical assistance of PayPal has provided me with a PHP demo working example of the whole operation. If you or some one are interested let me share this code, I'm attaching the file here.

From this demo I started creating the module. I also attaching here, how far I have arrived:

  • The module installs correctly, with some fields for contents, you can add the paid system with the Padloder module, the forms render correctly in Confermation Page and JSON is compiled correctly.

Form Paypal to make calls, you need a Sandbox account set up as a PayPal Business PRO. ( not just PayPal Business ).

EDIT

I deleted the module because it makes no sense to keep around something that doesn't work.
I'm think to be close so I will post finished version later

demoPPCPadv3DSEC.zip

Link to comment
Share on other sites

  • Marco Ro changed the title to Fetch to page in modules (PayPal Commercial Platform Serve-side)

UPDATE

Hi @kongondo So, I'm close to find a solution and make the Module works. But I need some help to the last steps.

For let the modules works I have to create a template with a PHP file in site/templates that includes the external library.
This way I can send the data and get the answer. I just don't understand why the call landing page gives me error 301 and all values are NULL or empty arrays

I fetch the data form the Confermation page in this way 

const data = { id: payload.orderId };
return fetch('".$capture."', { // this is in /site/templates/capture-order.php which has its own url
	method: 'post',
	headers: {
		'Accept': 'application/json',
		'Content-Type': 'application/json',
	},
	body: JSON.stringify(data)
})
.then(function(res) {
	return res.json();
}).then(function(data) {
	console.log('data->' , data);
	alert('ok');
	return data.id;
});

I try to receive data in these ways, but not one works

$json = file_get_contents('php://input');
var_dump($json);

$orderid = $json;
var_dump($orderid);

$data = json_decode($json);
var_dump($data->id);

$data['id'];
var_dump($data['id']);

Now I can't understand if the problem is on the error 301 or in the way i get the JSON.
I test the url and there isn't redirect.

Link to comment
Share on other sites

  • Marco Ro changed the title to [UPDATE] Fetch to page in modules (PayPal Commercial Platform Serve-side)

Hi @kongondo

I have definitely taken some steps forward! I'm able to do the server-side transaction with card.
The problem was that we have the site in multilingual I had to add the language path. In this way I can make the call and a credit card transaction is done correctly.

Now the problem, which I don't know if it can be solved, is the answer call. I see the response because I prints this in the capture-order page.  However, the response in the confirmation page is not sent to me from the server.

So, I do this:

From checkout/confirmation/ --> fetch a request to process payment to capture-order.php (that is a page in site/templates with a url) --> Then I need an answer in checkout/confirmation/ to finish the process.

But this not arrive, could be because ProcessWire blocks the call back ?
Is there a way to get the answer for this call?

If you want I can share my code. It works but is ugly. 

Link to comment
Share on other sites

  • 1 month later...

Hi Marco,

It would be great to have a quick way to add "Paypal" as a payment gateway easily to Processwire and I am looking forward to trying out your new module when it is compete.

In the meantime, I have been using an insecure method, but one that has not yet been abused to take a simple transaction with "Paypal".

It does not handshake with Paypal, but does know the url of the site page that it is called from and appears to work quite well in practice. Although, it is not exactly comprehensive it does take you to a "Paypal" shopping cart that takes care of multiple instances of different products doing all the hard work.

All you need is a "Paypal" email address a product description, a price and set the currency.

Obviously, it does not remove stock or accomplish many of the more comprehensive objectives regarding taxes and shipping, but as long as you populate the fields, which could be dynamically from Processwire, you can make a sale and "Paypal" keeps all the records.

The image for the "Purchase" is Bootstrap based, but you can replace this with your own image or styling.

Here is the Processwire Paypal Gateway code to cut-and-paste into any page template :-

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
  <!-- Identify your business so that you can collect the payments. -->
  <input type="hidden" name="business" value="YOUR_PAYPAL_EMAIL_ADDRESS">

  <!-- Specify a PayPal Shopping Cart Add to Cart button. -->
  <input type="hidden" name="cmd" value="_cart">
  <input type="hidden" name="add" value="1">

  <!-- Specify details about the item that buyers will purchase. -->
  <input type="hidden" name="item_name" value="YOUR PRODUCT DESCRIPTION - INCLUDE shipping in TOTAL">
  <input type="hidden" name="amount" value="150">
  <input type="hidden" name="currency_code" value="GBP">
  <!-- Display the payment button. -->
  <input class="btn btn-primary btn--pp img-responsive" style="margin: 0 auto;" type="submit" name="submit" value="Purchase">
  <img alt="" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

This could be developed further if necessary to include more features, but maybe it is better to wait for your module?

Regards,

Hackasacka

 

  • Like 1
Link to comment
Share on other sites

Hi @Hackasacka, thank you for share.

This is interesting, but what I needed was a server side operation, because  the PayPal Platform Commerce version active more PayPal features, like card payment for no PayPal account.

In the end I finish the module, is a bit row respect all the ProcessWire Module because it is my first module, but works well. I use it form 1 moth without problems.
You can find it here:

or here: https://github.com/MarcooRo/processwire-PayPal-Commerce-Platform

Link to comment
Share on other sites

Hi Marco,

That's no problem and I look forward to trying it out now there is a version to test.

Incidentally, the above code does have the option to pay with a credit card. However, you would need to process the "Instant Payment Notification" to confirm the sale at the server side if you would like to interact with the process.

One advantage of this code is the ease of use and also it is unnecessary to take any details of the third party buyer as Paypal processes this themselves. Thereby, if the buyer is already logged into their Paypal account two mouse clicks results in a sale (no complicated forms to discourage continuing). It may not be ideal to have an express checkout solution if more details are needed before a sale can take place with regards to shipping and taxes, but it would be possibe to add more server side validation before posting the form too.

Simple HTML Form Basics for PayPal Payments Standard

https://developer.paypal.com/api/nvp-soap/paypal-payments-standard/integration-guide/formbasics/

Regards,

Hackasacka

Link to comment
Share on other sites

Interesting I see that is a really minimal code, but what we needed was different.

The PayPal Platform Commerce version let you pay using card without any PayPal account. So, PayPal works like Stripe, he make a connection with the customer's back account and make the 3d security check, so user don't pay using PayPal but with a tool of PayPal. (this also have a less fee than Stripe).
Other nice thing of this version, like the old one, it integrate the local payment method like bank transfert. Also, here in Italy is not ready yet, but in the future will be possible have the payments in installments for customer, where PayPal pay all the amount to you but the customer can split into a maximum of 3/4 installments.

 

Link to comment
Share on other sites

Hi Marco,

It might be simpler for you to just try the above code to see for yourself the result (just requires any valid email here not necessarily a Paypal one ):-

<input type="hidden" name="business" value="YOUR_PAYPAL_EMAIL_ADDRESS">

It is possible to pay with a credit card just like "Stripe" (see bottom right of image included) too. Obviously, this would take more interaction before the transaction is completed compared with using a Paypal account directly. Paypal seem to try to obfuscate this option typically. I think it it obvious enough in this example.

However, if your version has more features available now and in the future it probably makes sense to use your module instead.

Regards,

Hackasacka

paypal-standard-html-payment-form.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...