Skip to content
This repository has been archived by the owner on Sep 29, 2023. It is now read-only.

Adding Checkout JS to existing Payment with PayPal sample #963

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

randstraw
Copy link

Adding Checkout JS to existing Payment with PayPal sample

Copy link
Contributor

@jaypatel512 jaypatel512 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the sample needs to be split in such a way that we can show how to create a payment using paypal, a separate js page, that shows how to render the button, and third on how to execute.

$payment->create($apiContext);
} catch (Exception $ex) {
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created Payment Using PayPal. Please visit the URL to Approve. -> Error creating Payment

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy and Paste from existing the CreatePayment example. What do you suggest?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add changes to both.

// The API response provides the url that you must redirect
// the buyer to. Retrieve the url from the $payment->getApprovalLink()
// method
$approvalUrl = $payment->getApprovalLink();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We won't need this.


// Checkout JS https://developer.paypal.com/demo/checkout/#/pattern/server
// NOTE: The checkout.js script should be added to your head element not directly to the body as shown in the sample here.
echo '<script src="https://www.paypalobjects.com/api/checkout.js"></script>';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to just finish the PHP script here, and load the script as a normal HTML tag.

<!DOCTYPE html>
<html>

<?php
... //This is where all our PHP code goes
?>

<head>
   <script src="https://www.paypalobjects.com/api/checkout.js"></script>
    ... // rest of your js code
</head>
<body>

</body>
</html>



// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Created Payment Using PayPal. Please click the PayPal Checkout button to Approve.", "Payment", $payment->id . "<br>Click here to Approve the Payment:<br> <div id=\"paypal-button-container\"></div>", $request, $payment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do not need this.

Copy link
Author

@randstraw randstraw Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will refactor per an above comment, in the current state it is needed because of this
<div id=\"paypal-button-container\"></div> output.

@@ -112,6 +112,6 @@
$approvalUrl = $payment->getApprovalLink();

// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", $payment->id . "<br>Please visit the URL to Approve: <a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would print Please visit the URL to Approve. twice.

// onAuthorize() is called when the buyer approves the payment
onAuthorize: function(data, actions) {
// Redirect to existing Execute Payment
return actions.redirect();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other options than doing a redirect ? Can I fetch all the relevant field here, and make a normal HTTP post call to my server to do an execute for me ? It would be nice to mention the most common flow used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the simplest way with the existing sample set up, I plan on creating another example with Ajax calls using the PayPal request object that is built into the Checkout library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should just stick to one. Let people do other's from documentation

@gety9
Copy link

gety9 commented Feb 2, 2018

@jaypatel512, @pp-randy Any reason why it's not merged to master yet?

@jaypatel512
Copy link
Contributor

Hey @gety9 ! We are still waiting for the changes we mentioned in our PR taken care of. There are many ways we can create a sample, and we want to present the best one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants