Пример #1
0
<?php

include 'Paypal.class.php';
include 'PaypalPayment.class.php';
$ppPaymentObj = new PaypalPayment(true);
$ppPaymentObj->sendToExpress(100.0, 'http://www.mystore.com/paypal/review.php?payment=paypal', 'Mystore.com Order');
        //make sure the response is VERFIED and that items price and currency are correct
        if ($ret == 'VERIFIED' && $_POST['payment_status'] == 'Completed' && isUnique($_POST['txn_id']) && $_POST['receiver_email'] == '*****@*****.**' && $_POST['mc_gross'] == '1.00' && $_POST['mc_currency'] == 'USD' & $_POST['item_name'] == 'ITEM NAME XXX' && $_POST['item_name'] == 'ITEM NAME XXX') {
            ///success code here
        } else {
            //log failed.
        }
    }
    //determines if a given transaction is unique
    private function isUnique($txn_id)
    {
        //use data attribute of the Transaction module
        return true;
    }
}
class User
{
    private $email;
    private $balance;
    public function __construct($e, $b)
    {
        $this->email = $e;
        $this->balance = $b;
    }
    public function __get($key)
    {
        return $this->{$key};
    }
}
$p = new PaypalPayment('seller_1257453128_biz_api1.hotmail.co.uk', '1257453132', 'AFcWxV21C7fd0v3bYYYRCpSSRl31Aq0ieLDgl8-TejuLH.olLgv6IgXf');
$p->massPay(array(new User('*****@*****.**', '5.00')));
//$p->IPN();
Пример #3
0
<?php

include 'Paypal.class.php';
include 'PaypalPayment.class.php';
$orderID = $_GET['orderID'];
$amount = 100.0;
$ppPaymentObj = new PaypalPayment(true);
$paymentType = $_GET['payment'];
switch ($paymentType) {
    case 'paypal':
        echo 'Express Transaction: ' . $ppPaymentObj->confirmExpress($amount, $orderID);
        break;
    case 'card':
        $ppPaymentObj->setCardInfo('4111111111111111', 'Visa', '122015', '111');
        $ppPaymentObj->setBillingInfo('John', 'Doe', 'None', '123 Any Street', 'Anytown', 'CA', '90000', 'US');
        echo 'Direct Transaction: ' . $ppPaymentObj->payWithCard($amount, $orderID);
        break;
}
 function process_ipn_response($request = null)
 {
     if (!defined('PAYPAL_DEBUG_MODE')) {
         define("PAYPAL_DEBUG_MODE", false);
     }
     // this prevents some kind of error in the core
     $_SESSION = null;
     if (DEBUG_MODE) {
         SS_Log::add_writer(new SS_LogFileWriter(__DIR__ . "/log/paypal.transactions.txt"), SS_Log::WARN, '>');
     }
     if (DEBUG_MODE) {
         SS_Log::log("IPN Started!", SS_Log::DEBUG);
     }
     // parse post variables, reformat the data to be sent back via socket
     $data = "cmd=_notify-validate";
     foreach ($_POST as $key => $value) {
         $value = urlencode(stripslashes($value));
         $data .= "&" . $key . "=" . $value;
     }
     // post back to PayPal system to validate
     $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
     $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
     $header .= "Host: www.paypal.com\r\n";
     $header .= "Connection: close\r\n";
     $header .= "Content-Length: " . strlen($data) . "\r\n\r\n";
     $response = "NONE";
     // send back the info
     $socket_handle = fsockopen("ssl://www.paypal.com", 443, $errno, $errstr, 30);
     if (DEBUG_MODE) {
         SS_Log::log("header_debug:\n" . print_r($header, true) . "\n\n", SS_Log::DEBUG);
     }
     if (DEBUG_MODE) {
         SS_Log::log("data_debug:\n" . print_r($data, true) . "\n\n", SS_Log::DEBUG);
     }
     if ($socket_handle) {
         fputs($socket_handle, $header . $data);
         while (!feof($socket_handle)) {
             $response = fgets($socket_handle, 1024);
             $response = trim($response);
             if (DEBUG_MODE) {
                 SS_Log::log("response_debug:\n" . print_r($response, true) . "\n\n", SS_Log::DEBUG);
             }
             if (strcmp($response, "VERIFIED") == 0) {
                 $response = "VERIFIED";
             } else {
                 if (strcmp($response, "INVALID") == 0) {
                     $response = "INVALID";
                 }
             }
         }
         fclose($socket_handle);
     }
     if (DEBUG_MODE) {
         SS_Log::log("paypal response: " . $response, SS_Log::DEBUG);
     }
     if (DEBUG_MODE) {
         SS_Log::log(print_r($_POST, true), SS_Log::DEBUG);
     }
     if ($response == "INVALID") {
         // we only care about completed interactions
         exit(0);
     }
     // SUCCESS - Do something with the data
     $Payment = new PaypalPayment();
     $Payment->PaypalStorePageID = $this->ID;
     $Payment->Date = SS_Datetime::now();
     $Payment->TransactionID = isset($_POST['txn_id']) ? $_POST['txn_id'] : $_POST['ipn_track_id'];
     $Payment->GatewayResponse = implode("\n", $_POST);
     $Payment->Amount = isset($_POST['amount3']) ? $_POST['amount3'] : (isset($_POST['payment_gross']) ? $_POST['payment_gross'] : (isset($_POST['mc_gross']) ? $_POST['mc_gross'] : 0));
     $Payment->ItemID = isset($_POST['item_number']) ? $_POST['item_number'] : null;
     $Payment->ItemName = isset($_POST['item_name']) ? $_POST['item_name'] : null;
     $Payment->Email = isset($_POST['payer_email']) ? $_POST['payer_email'] : null;
     $Payment->Status = isset($_POST['payment_status']) ? $_POST['payment_status'] : null;
     $Payment->Name = (isset($_POST['first_name']) ? $_POST['first_name'] : null) . ' ' . (isset($_POST['last_name']) ? $_POST['last_name'] : null);
     $Payment->Street = isset($_POST['address_street']) ? $_POST['address_street'] : null;
     $Payment->City = isset($_POST['address_city']) ? $_POST['address_city'] : null;
     $Payment->State = isset($_POST['address_state']) ? $_POST['address_state'] : null;
     $Payment->Country = isset($_POST['address_country']) ? $_POST['address_country'] : null;
     $Payment->Zip = isset($_POST['address_zip']) ? $_POST['address_zip'] : null;
     $Payment->PayerID = isset($_POST['payer_id']) ? $_POST['payer_id'] : null;
     $Payment->write();
     $Payment->OnSuccessfulPayment();
     return $Payment;
 }
Пример #5
0
<?php

include 'Paypal.class.php';
include 'PaypalPayment.class.php';
$ppPaymentObj = new PaypalPayment(true);
$paymentType = $_GET['payment'];
switch ($paymentType) {
    case 'paypal':
        $ppPaymentObj->getExpressInfo($_GET['token']);
        $ppPaymentObj->print_rp($ppPaymentObj->getBillingInfo());
        $ppPaymentObj->print_rp($ppPaymentObj->getShippingInfo());
        break;
    case 'card':
        break;
}
?>
<a href="confirm.php?payment=<?php 
echo $paymentType;
?>
">Yes, Place Order!</a>
    if ($key != 'extra') {
        $req .= "&{$key}={$value}";
    }
}
// Post back to PayPal to validate
if (!$sandbox) {
    $curl = curl_init('https://www.paypal.com/cgi-bin/webscr');
} else {
    $curl = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
}
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $req);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$res = curl_exec($curl);
if (strcmp($res, 'VERIFIED') == 0) {
    PaypalPayment::processStandardPayment();
    if ($email_admin) {
        $emailtext = '';
        foreach ($_REQUEST as $key => $value) {
            $emailtext .= $key . ' = ' . $value . '\\n\\n';
        }
        mail(osc_contact_email(), 'OSCLASS PAYPAL DEBUG', $emailtext . '\\n\\n ---------------- \\n\\n' . $req);
    }
} else {
    if (strcmp($res, 'INVALID') == 0) {
        // INVALID: Do nothing
    }
}
Пример #7
0
 public function hookPayment($params)
 {
     if (!$this->active) {
         return;
     }
     include _PS_MODULE_DIR_ . 'paypalapi/payment/paypalpayment.php';
     $ppPayment = new PaypalPayment();
     return $ppPayment->home($params);
 }
Пример #8
0
 public function execute($payPalId, $payerID = null)
 {
     if ($payerID == null) {
         $payerID = $this->getPayer->getPayerInfo()->getPayerId();
     }
     if ($this->getStatus($payPalId) == "created") {
         $payment = $this->getPayment($payPalId);
         $execution = PaypalPayment::PaymentExecution();
         $execution->setPayerId($payerID);
         try {
             $payment->execute($execution, $this->_apiContext);
         } catch (\PayPal\Exception\PPConnectionException $ex) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             dd($ex->getData());
             exit(1);
         }
     }
 }