コード例 #1
0
ファイル: PayPalAdapter.php プロジェクト: hypesystem/php-pay
 private function getOptionsWithLineItems(Order $order)
 {
     $options = $this->options;
     $total = 0;
     $lineItemCount = $order->getLineCount();
     for ($i = 0; $i < $lineItemCount; $i++) {
         $item = $order->getLine($i);
         $options["L_PAYMENTREQUEST_0_NAME" . $i] = urlencode($item["name"]);
         //TODO: Maybe L_PAYMENTREQUEST_0_{NUMBER,DESC}.$i (an item number) is required?
         $options["L_PAYMENTREQUEST_0_AMT" . $i] = urlencode(number_format($item["priceBeforeTax"], 2));
         //TODO: Support quantities
         $options["L_PAYMENTREQUEST_0_QTY" . $i] = urlencode(1);
     }
     return $options;
 }
コード例 #2
0
ファイル: OrderTest.php プロジェクト: hypesystem/php-pay
 public function testGettingTotalTax()
 {
     $order = new Order(10, array(array("name" => "hello", "price" => 100), array("second", 60), array("quantized", 120, 3), array("name" => "labelled", "price" => 200, "quantity" => 4)));
     $this->assertEquals($order->getTotalTax(), 9.09 + 5.45 + 10.91 + 18.18);
 }
コード例 #3
0
ファイル: startPayment.php プロジェクト: hypesystem/php-pay
use PhpPay\Order;
use PhpPay\PayPal\PayPalAdapter;
use PhpPay\PaymentHandler;
include "../../vendor/autoload.php";
function phpPayAutoloader($class)
{
    if (strpos($class, "PhpPay\\") == 0) {
        $class = str_replace("\\", "/", substr($class, 7));
        $file = "../../src/{$class}.php";
        if (file_exists($file)) {
            include $file;
        }
    }
}
spl_autoload_register("phpPayAutoloader");
$thisUrl = $_REQUEST["thisUrl"];
// Our simple little requester
$requester = new Requester();
// This is the paypal-specific setup part
$returnUrl = $thisUrl . "endPayment.php?id=" . md5(rand());
$cancelUrl = $thisUrl . "cancelPayment.php?id=" . md5(rand());
$paypalAdapter = new PayPalAdapter($requester, $returnUrl, $cancelUrl, array("user" => $_REQUEST["user"], "pwd" => $_REQUEST["pwd"], "signature" => $_REQUEST["signature"]), true);
$paymentHandler = new PaymentHandler($paypalAdapter);
// With this setup, we can prepare a payment (this will be the same for any adapter)
$order = new Order(10, array(array("Price item 1", 120), array("Price item 2", 190)));
$order->addShipping(100);
$payment = $paymentHandler->preparePayment($order);
//We need to save the payment somewhere locally, to get it back later.
file_put_contents($paymentId . ".json", $payment->getSerializedData());
//Now we can use the payment's checkout url to do the checkout
header("Location: " . $payment->getCheckoutUrl());