-
Notifications
You must be signed in to change notification settings - Fork 108
Adding Checkout JS to existing Payment with PayPal sample #963
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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>'; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@jaypatel512, @pp-randy Any reason why it's not merged to master yet? |
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. |
Adding Checkout JS to existing Payment with PayPal sample