forked from LiveCarta/PayPal-PHP-SDK
Initial commit
This commit is contained in:
82
tests/PayPal/Test/Api/PaymentTest.php
Normal file
82
tests/PayPal/Test/Api/PaymentTest.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace PayPal\Test\Api;
|
||||
|
||||
|
||||
use PayPal\Api\RedirectUrls;
|
||||
|
||||
use PayPal\Api\Address;
|
||||
use PayPal\Api\Amount;
|
||||
use PayPal\Api\CreditCard;
|
||||
use PayPal\Api\Payer;
|
||||
use PayPal\Api\Payment;
|
||||
use PayPal\Api\FundingInstrument;
|
||||
use PayPal\Api\Transaction;
|
||||
use PayPal\Test\Constants;
|
||||
|
||||
class PaymentTest extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
private $payments;
|
||||
|
||||
public static function createPayment() {
|
||||
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturn_url("http://localhost/return");
|
||||
$redirectUrls->setCancel_url("http://localhost/cancel");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setRedirect_urls($redirectUrls);
|
||||
$payment->setPayer(PayerTest::createPayer());
|
||||
$payment->setTransactions(array(TransactionTest::createTransaction()));
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
public static function createNewPayment() {
|
||||
$payer = new Payer();
|
||||
$payer->setPayment_method("credit_card");
|
||||
$payer->setFunding_instruments(array(FundingInstrumentTest::createFundingInstrument()));
|
||||
|
||||
$transaction = new Transaction();
|
||||
$transaction->setAmount(AmountTest::createAmount());
|
||||
$transaction->setDescription("This is the payment description.");
|
||||
|
||||
$redirectUrls = new RedirectUrls();
|
||||
$redirectUrls->setReturn_url("http://localhost/return");
|
||||
$redirectUrls->setCancel_url("http://localhost/cancel");
|
||||
|
||||
$payment = new Payment();
|
||||
$payment->setIntent("sale");
|
||||
$payment->setRedirect_urls($redirectUrls);
|
||||
$payment->setPayer($payer);
|
||||
$payment->setTransactions(array($transaction));
|
||||
|
||||
return $payment;
|
||||
}
|
||||
|
||||
public function setup() {
|
||||
$this->payments['full'] = self::createPayment();
|
||||
$this->payments['new'] = self::createNewPayment();
|
||||
}
|
||||
|
||||
public function testSerializeDeserialize() {
|
||||
$p2 = new Payment();
|
||||
$p2->fromJson($this->payments['full']->toJSON());
|
||||
$this->assertEquals($p2, $this->payments['full']);
|
||||
}
|
||||
|
||||
public function testOperations() {
|
||||
|
||||
$p1 = $this->payments['new'];
|
||||
|
||||
$p1->create();
|
||||
$this->assertNotNull($p1->getId());
|
||||
|
||||
$p2 = Payment::get($p1->getId());
|
||||
$this->assertNotNull($p2);
|
||||
|
||||
$paymentHistory = Payment::all(array('count' => '10'));
|
||||
$this->assertNotNull($paymentHistory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user