paypal / merchant-sdk-php

PHP SDK for integrating with PayPal's Express Checkout / MassPay / Web Payments Pro APIs
Other
230 stars 201 forks source link

status: archive

PayPal PHP Merchant SDK

The merchant SDK can be used for integrating with the Express Checkout, Mass Pay, Web Payments Pro APIs.

TLSv1.2 Update

The Payment Card Industry (PCI) Council has mandated that early versions of TLS be retired from service. All organizations that handle credit card information are required to comply with this standard. As part of this obligation, PayPal is updating its services to require TLS 1.2 for all HTTPS connections. At this time, PayPal will also require HTTP/1.1 for all connections. Click here for more information

A new mode has been created to test if your server/machine handles TLSv1.2 connections. Please use tls mode instead of sandbox to verify. You can return back to sandbox mode once you have verified. Please have a look at this Sample Configuration.

POODLE Update

All these changes are included in the recent release, along with many other bug fixes.

Support

Please contact PayPal Technical Support for any live or account issues.

Prerequisites

PayPal's PHP Merchant SDK requires

Running the sample

To run the bundled sample, first copy the samples folder to your web server root. You will then need to install the SDK as a dependency using composer (PHP V5.3+ only).

Using the SDK

To use the SDK,

{
    "name": "me/shopping-cart-app",
    "require": {
        "paypal/merchant-sdk-php":"3.8.*"
    }
}

For example,

    // Sets config file path(if config file is used) and registers the classloader
    require("PPBootStrap.php");

    // Array containing credentials and confiuration parameters. (not required if config file is used)
    $config = array(
       'mode' => 'sandbox',
       'acct1.UserName' => 'jb-us-seller_api1.paypal.com',
       'acct1.Password' => 'WX4WTU3S8MY44S7F'
       .....
    );

    // Create request details
    $itemAmount = new BasicAmountType($currencyId, $amount);
    $setECReqType = new SetExpressCheckoutRequestType();
    $setECReqType->SetExpressCheckoutRequestDetails = $setECReqDetails;

    // Create request
    $setECReq = new SetExpressCheckoutReq();
    $setECReq->SetExpressCheckoutRequest = $setECReqType;
    ......

    // Perform request
    $paypalService = new PayPalAPIInterfaceServiceService($config);
    $setECResponse = $paypalService->SetExpressCheckout($setECReq);

    // Check results
    if(strtoupper($setECResponse->Ack) == 'SUCCESS') {
        // Success
    }  

Authentication

The SDK provides multiple ways to authenticate your API call.

    $paypalService = new PayPalAPIInterfaceServiceService($config);

    // Use the default account (the first account) configured in sdk_config.ini
    $response = $paypalService->SetExpressCheckout($setECReq);

    // Use a specific account configured in sdk_config.ini
    $response = $paypalService->SetExpressCheckout($setECReq, 'jb-us-seller_api1.paypal.com');

    // Pass in a dynamically created API credential object
    $cred = new PPCertificateCredential("username", "password", "path-to-pem-file");
    $cred->setThirdPartyAuthorization(new PPTokenAuthorization("accessToken", "tokenSecret"));
    $response = $paypalService->SetExpressCheckout($setECReq, $cred);

SDK Configuration

The SDK allows you to configure the following parameters-

Dynamic configuration values can be set by passing a map of credential and config values (if config map is passed the config file is ignored)

    $config = array(
       'mode' => 'sandbox',
       'acct1.UserName' => 'jb-us-seller_api1.paypal.com',
       'acct1.Password' => 'WX4WTU3S8MY44S7F'
       .....
    );
    $service  = new PayPalAPIInterfaceServiceService($config); 

Alternatively, you can configure the SDK via the sdk_config.ini file.

    define('PP_CONFIG_PATH', '/directory/that/contains/sdk_config.ini');
    $service  = new PayPalAPIInterfaceServiceService();

You can refer full list of configuration parameters in wiki page.

Instant Payment Notification (IPN)

Please refer to the IPN-README in 'samples/IPN' directory.

Links