2 namespace PayPal\Test\Api;
3 use PayPal\Api\RedirectUrls;
4 use PayPal\Api\Address;
6 use PayPal\Api\CreditCard;
8 use PayPal\Api\Payment;
9 use PayPal\Api\FundingInstrument;
10 use PayPal\Api\Transaction;
11 use PayPal\Test\Constants;
13 class PaymentTest extends \PHPUnit_Framework_TestCase {
17 public static function createPayment() {
19 $redirectUrls = new RedirectUrls();
20 $redirectUrls->setReturnUrl("http://localhost/return");
21 $redirectUrls->setCancelUrl("http://localhost/cancel");
23 $payment = new Payment();
24 $payment->setIntent("sale");
25 $payment->setRedirectUrls($redirectUrls);
26 $payment->setPayer(PayerTest::createPayer());
27 $payment->setTransactions(array(TransactionTest::createTransaction()));
32 public static function createNewPayment() {
34 $payer->setPaymentMethod("credit_card");
35 $payer->setFundingInstruments(array(FundingInstrumentTest::createFundingInstrument()));
37 $transaction = new Transaction();
38 $transaction->setAmount(AmountTest::createAmount());
39 $transaction->setDescription("This is the payment description.");
41 $redirectUrls = new RedirectUrls();
42 $redirectUrls->setReturnUrl("http://localhost/return");
43 $redirectUrls->setCancelUrl("http://localhost/cancel");
45 $payment = new Payment();
46 $payment->setIntent("sale");
47 $payment->setRedirectUrls($redirectUrls);
48 $payment->setPayer($payer);
49 $payment->setTransactions(array($transaction));
54 public function setup() {
55 $this->payments['full'] = self::createPayment();
56 $this->payments['new'] = self::createNewPayment();
59 public function testSerializeDeserialize() {
61 $p2->fromJson($this->payments['full']->toJSON());
62 $this->assertEquals($p2, $this->payments['full']);
65 public function testOperations() {
67 $p1 = $this->payments['new'];
70 $this->assertNotNull($p1->getId());
72 $p2 = Payment::get($p1->getId());
73 $this->assertNotNull($p2);
75 $paymentHistory = Payment::all(array('count' => '10'));
76 $this->assertNotNull($paymentHistory);