Jibin Mathew
Jibin Mathew

Reputation: 5122

Unknown error in paypal integration

I am trying to integrate Paypal to my website but its been a lot of chaos.

The documentation doesn't seem to match with the PHP SDK of theirs and hence its been a trouble please suggest appropriate integration method.

The code I have tried out is as follows :

<?php
    ini_set('max_execution_time', 300);
    require __DIR__  . '/bootstrap.php';
    // 3. Lets try to save a credit card to Vault using Vault API mentioned here
    // https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card
    $apiContext->setConfig(
    array(
        'log.LogEnabled' => true,
        'log.FileName' => 'PayPal.log',
        'log.LogLevel' => 'DEBUG'
      )
    );
    $creditCard = new \PayPal\Api\CreditCard();
    $creditCard->setType("visa")
        ->setNumber("403*************")
        ->setExpireMonth("09")
        ->setExpireYear("2020")
        ->setCvv2("123")
        ->setFirstName("J***")
        ->setLastName("M*****");
    $fi = new \PayPal\Api\FundingInstrument();
    $fi->setCreditcard($creditCard);
    $payer = new \PayPal\Api\Payer();
    $payer->setPaymentmethod('credit_card');
    $payer->setFundinginstruments(array($fi));
    $amount = new \PayPal\Api\Amount();
    $amount->setCurrency('USD');
    $amount->setTotal('7.47');
    $transaction = new \PayPal\Api\Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription('This is the payment transaction  description.');
    $payment = new \PayPal\Api\Payment();
    $payment->setIntent('sale');
    $payment->setPayer($payer);
    $payment->setTransactions(array($transaction));
    // 4. Make a Create Call and Print the Card
    try {
        //$creditCard->create($apiContext);   
        //$creditCard->create($apiContext);       
        $payment->create($apiContext);
        echo $payment;
    }catch (\PayPal\Exception\PayPalConnectionException $ex) {
         // This will print the detailed information on the exception. 
        //REALLY HELPFUL FOR DEBUGGING
        echo $ex->getData();
    }
    ?>

Upvotes: 1

Views: 802

Answers (1)

pp_MSI_Jenn
pp_MSI_Jenn

Reputation: 1599

If you are using Vault you need to have been approved to accept direct credit cards. You will need to make certain that the application that you have submitted for Rest API and Vault has been fully approved for direct credit cards.

From the PayPal Developer Site:

Store and use a customer credit card
Direct credit card payment and related features are restricted in some countries.

Vault Information

Here is additional information on Going Live with your Application:
Apps 101

Here are the instructions:

  1. Log into your developer account at developer.paypal.com
  2. Click on My Account
  3. Scroll Down to Direct Credit Cards
  4. Click on Enable
  5. Click Continue
  6. Fill out the information requested

Visual Representation

Upvotes: 1

Related Questions