PayPal\Service\PayPalAPIInterfaceServiceService::DoDirectPayment PHP Method

DoDirectPayment() public method

Service Call: DoDirectPayment
public DoDirectPayment ( DoDirectPaymentReq $doDirectPaymentReq, mixed $apiCredential = null ) : DoDirectPaymentResponseType
$doDirectPaymentReq PayPal\PayPalAPI\DoDirectPaymentReq
$apiCredential mixed - Optional API credential - can either be a username configured in sdk_config.ini or a ICredential object created dynamically
return PayPal\PayPalAPI\DoDirectPaymentResponseType
    public function DoDirectPayment($doDirectPaymentReq, $apiCredential = null)
    {
        $apiContext = new PPApiContext($this->config);
        $handlers = array(new PPMerchantServiceHandler($apiCredential, self::$SDK_NAME, self::$SDK_VERSION));
        $this->setStandardParams($doDirectPaymentReq->DoDirectPaymentRequest);
        $ret = new DoDirectPaymentResponseType();
        $resp = $this->call('PayPalAPIAA', 'DoDirectPayment', $doDirectPaymentReq, $apiContext, $handlers);
        $ret->init(PPUtils::xmlToArray($resp));
        return $ret;
    }

Usage Example

$cardDetails->ExpYear = $_POST['expDateYear'];
$cardDetails->CVV2 = $_POST['cvv2Number'];
$cardDetails->CardOwner = $payer;
$ddReqDetails = new DoDirectPaymentRequestDetailsType();
$ddReqDetails->CreditCard = $cardDetails;
$ddReqDetails->PaymentDetails = $paymentDetails;
$doDirectPaymentReq = new DoDirectPaymentReq();
$doDirectPaymentReq->DoDirectPaymentRequest = new DoDirectPaymentRequestType($ddReqDetails);
/*
 * 		 ## Creating service wrapper object
Creating service wrapper object to make API call and loading
Configuration::getAcctAndConfig() returns array that contains credential and config parameters
*/
$paypalService = new PayPalAPIInterfaceServiceService(Configuration::getAcctAndConfig());
try {
    /* wrap API method calls on the service object with a try catch */
    $doDirectPaymentResponse = $paypalService->DoDirectPayment($doDirectPaymentReq);
} catch (Exception $ex) {
    include_once "../Error.php";
    exit;
}
if (isset($doDirectPaymentResponse)) {
    echo "<table>";
    echo "<tr><td>Ack :</td><td><div id='Ack'>{$doDirectPaymentResponse->Ack}</div> </td></tr>";
    echo "<tr><td>TransactionID :</td><td><div id='TransactionID'>{$doDirectPaymentResponse->TransactionID}</div> </td></tr>";
    echo "</table>";
    echo "<pre>";
    print_r($doDirectPaymentResponse);
    echo "</pre>";
}
require_once '../Response.php';