Click here to Skip to main content
15,886,518 members

Setting up paypal-checkout-SDK with my shopping cart.

TheBigBearNow asked:

Open original thread
Hello Paypal,

I am working on putting your checkout SDK into my shopping cart. I been following the directions on the developers page and I have the buttons that open the paypal window on my page. I have a sandbox account. I can get the price correct from the cart to the paypal window but I have having problems with the actual product information. My problem is I am using JavaScript and inputting the cart total into the JSON object. I have the SDK and the examples and I see creating the sandbox environment client, how can I click the button and create my order in php to show the correct details in the paypal window. On my sandbox I get the correct total with the buyer account and the business account but the product details and payer info I want to grab the user info from the form I have and automatically insert them into the paypal window. Here is code I have and some of your example code I have been using. I found ways to do this the older way but on your developer site it says to use the new integration instead of the old way. My products are in the $_SESSION and user data is serialized
PHP
<div class="container">
    <div class="col-md-12 my-3">
        <button type="button" class="btn btn-primary">Test Details</button>
    </div>
    <div class="col-md-12">
        <a id="btnPayPal"></a>
    </div>
</div>
<script>
    var totalPrice = <?php echo $newtTotal; ?>;
paypal.Buttons({
        createOrder: function(data, actions) {
            // setup transaction
            return actions.order.create({
                payer: {
                    payer_info: {
                        email: '<?php echo $email; ?>',
                        first_name: '<?php echo $fname; ?>',
                        last_name: '<?php echo $lname; ?>'
                    }
                },
                purchase_units: [{
                   amount: {
                       value: totalPrice
                   }
                }]
            });
        },
        onApprove: function(data, actions) {
            // capture funds from transaction
            return actions.order.capture().then(function(details) {

                // show success msg to buyer
                // alert("Transaction success - " + details.payer.name.given_name);
                // call transaction to server save
                return fetch('/paypal-transaction-complete', {
                    method: 'post',
                    body: JSON.stringify({
                        orderID: data.orderID
                    })
                });
            });
        }
    }).render('#btnPayPal');
In the create order how can I call the php createorder()
<?php
namespace Sample\AuthorizeIntentExamples;
require __DIR__ . '/../../vendor/autoload.php';
use PayPalCheckoutSdk\Orders\OrdersCreateRequest;
use Sample\PayPalClient;

class CreateOrder{
private static function buildRequestBody(){
        return array(
            'intent' => 'AUTHORIZE',
            'application_context' =>
                array(),
'purchase_units' =>
                array(
                    0 =>
                        array(
'currency_code' => 'USD',
                         'value' => '220.00',
), 'items' =>
                                array(
                                    0 =>
                                        array(
                                            'name' => 'T-Shirt',
                                            'description' => 'Green XL',
                                            'sku' => 'sku01',
                                            'unit_amount' =>
                                                array(
                                                    'currency_code' => 'USD',
                                                    'value' => '90.00',
                                                ),
// The code is pieces copy and pasted out samples I’ll need.


I see the PayPalClient and GetOrder and CreateOrder I would like to setup my shopping cart correctly so I can use the paypalclient – paypal-checkout-sdk php project.

My project is in the Rest API panel in the paypal sandbox.

What I have tried:

building a order in full javascript but been told it is better to do it in php so the user cannot edit the order. now i want to have the order created and be able to use the paypal sdk to create get and submit the order to the paypal server for a transaction
Tags: Javascript, PHP, JSON, PayPal

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900