Setting PayPal PHP Application live

Flo

I followed some dudes tutorial on how to Charge People with PayPal using the PHP SDK. It all works like a charm as long as I'm in Testmode, but if I cange my API Keys to the "live" ones, I only get an HTTP Error 401. I understand that this is because I have to set the Application to "Live".

I followed the Guide on PayPals GitHub Page. (https://github.com/paypal/PayPal-PHP-SDK/wiki/Going-Live)

Dont worry, I dont do this for the acutal Web, I just want to get back into PHP and it drives me nuts that I am not able to configure this script.

I have the following "charge.php":

    require 'app/start.php';
use PayPal\Api\Payer;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Payment;

if(!isset($_POST['product'])){
    echo $_POST['product'];
    die("Nope");
}

    $product="Premium";
    $price="1.00";
    $shipping="0.00";
    $total = $price+$shipping;

    $payer = new Payer();
    $payer->setPaymentMethod('paypal');

    $item = new Item();
    $item->setName($product)
    ->setCurrency('EUR')
    ->setQuantity(1)
    ->setPrice($price);

    $itemList = new ItemList();
    $itemList->setItems([$item]);

    $details = new Details();
    $details->setShipping($shipping)
    ->setSubtotal($price);

    $amount = new Amount();
    $amount->setCurrency('EUR')
    ->setTotal($total)
    ->setDetails($details);

    $transaction = new Transaction();
    $transaction->setAmount($amount)
    ->setItemList($itemList)
    ->setDescription($product)
    //UserID 
    ->setInvoiceNumber(rand());

    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl('/paid.php?sucess=true')
    ->setCancelUrl('/paid.php?sucess=false');

    $payment = new Payment();
    $payment->setIntent('sale')
    ->setPayer($payer)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions([$transaction]);

    try{
        $payment->create($paypal);

    } catch (Exception $e){
        die($e);
    }

    $approvalUrl=$payment->getApprovalLink();
    header("Location: {$approvalUrl}");

And the following "start.php" with my API Credentials in it:

require 'vendor/autoload.php';

define('SITE_URL', '/charge.php');

$paypal = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
    'xx',
    'xx'
    )
);

Can someone give me a hint, where I need to confige the App to use PayPals Live API? I tried it in the carge.php, but I only get the PHP Error, that I use an undefined variable.

Im talking about the following Snipit from PayPals Github:

$apiContext->setConfig(
      array(
        ...
        'mode' => 'live',
        ...
      )
);

Any help would be much appreciated. Cheers, Flo

Flo

Okay, I figured it out. For anyone who has the same issue:

For the config array to work, you also have to put the Nameclass in there. So the correct "start.php" should look like this:

<?php

use \PayPal\Rest\ApiContext;
use \PayPal\Auth\OAuthTokenCredential;

require 'vendor/autoload.php';

define('SITE_URL', 'charge_paypal.php');

$paypal = new \PayPal\Rest\ApiContext(
    new \PayPal\Auth\OAuthTokenCredential(
    'x',
    'x'
    )
);

$paypal->setConfig([
    'mode' => 'live',
        'log.LogEnabled' => true,
        'log.FileName' => 'PayPal.log',
        'log.LogLevel' => 'FINE'
]);

?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Validate Paypal Live Account

Setting Paypal Checkout Price

Issue in PayPal live transaction if PayPal Balance is $0.00

Paypal - Payouts issue on live paypal envirnment

Where I get the Live AppID for Paypal Api? I use adaptiveaccounts-sdk-php 3.6.106

PayPal REST API (PHP SDK) successful transactions not showing in sandbox mode, showing in live mode

Why is setLandingPageType("billing") working in Sandbox but not in Live-Version in PAYPAL PHP REST API SDK WebProfile

How to make my django website live to the world after setting up my application with Digital Ocean Droplet?

Setting up reference transaction for paypal

Paypal Integration with php not forwarding to paypal

setting up server on bluehost for laravel application and having issue with php -v

Setting TeX Live path for root

iPhone application PayPal Integration

Paypal integration to android application

Paypal integration to Flask application

Paypal live payment failed to charge customer

Getting clientID and clientSecret for live paypal account

How to move PayPal Checkout to live production?

paypal client authentication failed while going live

Paypal Switching from Sandbox to Live - Swift SDK

NOT_AUTHORIZED error – only in PayPal Live environment

Paypal DPRP is disable for live account error?

Paypal (India to India) payment error in live mode

Application Insights Live Stream

Live reload for electron application

PHP Slim 4 HttpNotFoundException -- Routes not found when moving application to live server

Setting PayPal return URL and making it auto return?

PayPal Checkout JS SDK - dynamically setting an amount

Paypal PHP SDK Error

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive