예제 #1
0
<?php

require_once '../includes/config.php';
require_once '../autoload.php';
$PayPalConfig = array('Sandbox' => $sandbox, 'APIUsername' => $api_username, 'APIPassword' => $api_password, 'APISignature' => $api_signature, 'PrintHeaders' => $print_headers, 'LogResults' => $log_results, 'LogPath' => $log_path);
$PayPal = new angelleye\PayPal\PayPal($PayPalConfig);
$DPFields = array('paymentaction' => 'Sale', 'ipaddress' => $_SERVER['REMOTE_ADDR'], 'returnfmfdetails' => '1');
$CCDetails = array('creditcardtype' => 'MasterCard', 'acct' => '5522340006063638', 'expdate' => '022016', 'cvv2' => '456', 'startdate' => '', 'issuenumber' => '');
$PayerInfo = array('email' => '*****@*****.**', 'payerid' => '', 'payerstatus' => '', 'business' => '');
$PayerName = array('salutation' => '', 'firstname' => 'Tester', 'middlename' => '', 'lastname' => 'Testerson', 'suffix' => '');
$BillingAddress = array('street' => '707 W. Bay Drive', 'street2' => '', 'city' => 'Largo', 'state' => 'FL', 'countrycode' => 'US', 'zip' => '33770', 'phonenum' => '');
$ShippingAddress = array('shiptoname' => '', 'shiptostreet' => '', 'shiptostreet2' => '', 'shiptocity' => '', 'shiptostate' => '', 'shiptozip' => '', 'shiptocountrycode' => '', 'shiptophonenum' => '');
$PaymentDetails = array('amt' => '3.00', 'currencycode' => 'USD', 'itemamt' => '', 'shippingamt' => '', 'handlingamt' => '', 'taxamt' => '', 'desc' => 'Testing Payments Pro DESC Field', 'custom' => 'TEST', 'invnum' => '', 'buttonsource' => '', 'notifyurl' => '');
$OrderItems = array();
$Item = array('l_name' => 'Test Widget', 'l_desc' => 'This is a test widget description.', 'l_amt' => '1.00', 'l_number' => 'ABC-123', 'l_qty' => '1', 'l_taxamt' => '', 'l_ebayitemnumber' => '', 'l_ebayitemauctiontxnid' => '', 'l_ebayitemorderid' => '');
array_push($OrderItems, $Item);
$Item = array('l_name' => 'Test Widget 2', 'l_desc' => 'This is a test widget description.', 'l_amt' => '2.00', 'l_number' => 'ABC-XYZ', 'l_qty' => '1', 'l_taxamt' => '', 'l_ebayitemnumber' => '', 'l_ebayitemauctiontxnid' => '', 'l_ebayitemorderid' => '');
array_push($OrderItems, $Item);
$PayPalRequestData = array('DPFields' => $DPFields, 'CCDetails' => $CCDetails, 'PayerInfo' => $PayerInfo, 'PayerName' => $PayerName, 'BillingAddress' => $BillingAddress, 'PaymentDetails' => $PaymentDetails, 'OrderItems' => $OrderItems);
$PayPalResult = $PayPal->DoDirectPayment($PayPalRequestData);
$_SESSION['transaction_id'] = isset($PayPalResult['TRANSACTIONID']) ? $PayPalResult['TRANSACTIONID'] : '';
echo '<pre />';
print_r($PayPalResult);
 $_SESSION['shippingInfo'] = isset($_POST['shippingInfo']) ? $_POST['shippingInfo'] : array();
 ##########[ Direct Payment ]############
 // Create new PayPal object
 $DPFields = array('paymentaction' => $_SESSION['transaction_type'], 'ipaddress' => $_SERVER['REMOTE_ADDR'], 'returnfmfdetails' => '1');
 $CCDetails = array('creditcardtype' => $_SESSION['cc_type'], 'acct' => $_SESSION['cc_number'], 'expdate' => $_SESSION['cc_expdate'], 'cvv2' => $_SESSION['cvv2']);
 $PayerInfo = array('email' => $_SESSION['billing_email'], 'business' => '');
 $PayerName = array('firstname' => $_SESSION['billing_first_name'], 'lastname' => $_SESSION['billing_last_name']);
 $BillingAddress = array('street' => $_SESSION['billing_street1'], 'street2' => $_SESSION['billing_street2'], 'city' => $_SESSION['billing_city'], 'state' => $_SESSION['billing_state'], 'countrycode' => $_SESSION['billing_country_code'], 'zip' => $_SESSION['billing_postal_code'], 'phonenum' => $_SESSION['billing_phone']);
 if (isset($_POST['shippingDisabled']) && $_POST['shippingDisabled'] == true) {
     $ShippingAddress = array();
 } else {
     $ShippingAddress = array('shiptoname' => $_SESSION['shipping_first_name'] . " " . $_SESSION['shipping_last_name'], 'shiptostreet' => $_SESSION['shipping_street1'], 'shiptostreet2' => $_SESSION['shipping_street2'], 'shiptocity' => $_SESSION['shipping_city'], 'shiptostate' => $_SESSION['shipping_state'], 'shiptozip' => $_SESSION['shipping_postal_code'], 'shiptocountrycode' => $_SESSION['shipping_country_code'], 'shiptophonenum' => $_SESSION['shipping_phone']);
 }
 $PaymentDetails = array('amt' => $_SESSION['amount'], 'currencycode' => $config['CurrencyCode'], 'itemamt' => $_SESSION['subtotal'], 'shippingamt' => $_SESSION['shipping_amount'], 'handlingamt' => $_SESSION['handling_amount'], 'taxamt' => $_SESSION['tax_amount'], 'desc' => 'PayPal Payments Pro Virtual Terminal Sale', 'custom' => '', 'invnum' => $_SESSION['invoice'], 'buttonsource' => '', 'notifyurl' => '');
 $DPData = array('DPFields' => $DPFields, 'CCDetails' => $CCDetails, 'PayerInfo' => $PayerInfo, 'PayerName' => $PayerName, 'BillingAddress' => $BillingAddress, 'ShippingAddress' => $ShippingAddress, 'PaymentDetails' => $PaymentDetails);
 $_SESSION['DPResult'] = $paypal->DoDirectPayment($DPData);
 // Write to transaction log
 if (isset($config['LogEnabled']) && $config['LogEnabled']) {
     logTransaction($_SESSION['DPResult'], $config['LogFilePath']);
 }
 if (strtoupper($_SESSION['DPResult']['ACK']) == 'FAILURE' || strtoupper($_SESSION['DPResult']['ACK']) == 'FAILUREWITHWARNING') {
     $_SESSION['paypal_errors'] = $_SESSION['DPResult']['ERRORS'];
     $PayPalErrors = $_SESSION['paypal_errors'];
     $result_data_html = '<ul>';
     foreach ($PayPalErrors as $error) {
         foreach ($error as $k => $v) {
             $result_data_html .= '<li><strong>' . $k . '</strong>&nbsp;' . $v . '</li>';
         }
     }
     $result_data_html .= '</ul>';
     echo json_encode(array('result' => 'error', 'result_data' => $result_data_html));