// This sample code demonstrates how you can authorize a payment. // API used: /v1/payments/authorization // https://developer.paypal.com/webapps/developer/docs/integration/direct/capture-payment/#authorize-the-payment require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Address; use PayPal\Api\Amount; use PayPal\Api\FundingInstrument; use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\PaymentCard; use PayPal\Api\Transaction; // The biggest difference between creating a payment, and authorizing a payment is to set the intent of payment // to correct setting. In this case, it would be 'authorize' $addr = new Address(); $addr->setLine1("3909 Witmer Road")->setLine2("Niagara Falls")->setCity("Niagara Falls")->setState("NY")->setPostalCode("14305")->setCountryCode("US")->setPhone("716-298-1822"); $paymentCard = new PaymentCard(); $paymentCard->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper")->setBillingCountry("US")->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setPaymentCard($paymentCard); $payer = new Payer(); $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi)); $amount = new Amount(); $amount->setCurrency("USD")->setTotal(1); $transaction = new Transaction(); $transaction->setAmount($amount)->setDescription("Payment description."); $payment = new Payment(); // Setting intent to authorize creates a payment // authorization. Setting it to sale creates actual payment $payment->setIntent("authorize")->setPayer($payer)->setTransactions(array($transaction)); // For Sample Purposes Only. $request = clone $payment;
/** * @depends testSerializationDeserialization * @param PaymentCard $obj */ public function testGetters($obj) { $this->assertEquals($obj->getId(), "TestSample"); $this->assertEquals($obj->getNumber(), "TestSample"); $this->assertEquals($obj->getType(), "TestSample"); $this->assertEquals($obj->getExpireMonth(), 123); $this->assertEquals($obj->getExpireYear(), 123); $this->assertEquals($obj->getStartMonth(), "TestSample"); $this->assertEquals($obj->getStartYear(), "TestSample"); $this->assertEquals($obj->getCvv2(), "TestSample"); $this->assertEquals($obj->getFirstName(), "TestSample"); $this->assertEquals($obj->getLastName(), "TestSample"); $this->assertEquals($obj->getBillingCountry(), "TestSample"); $this->assertEquals($obj->getBillingAddress(), AddressTest::getObject()); $this->assertEquals($obj->getExternalCustomerId(), "TestSample"); $this->assertEquals($obj->getStatus(), "TestSample"); $this->assertEquals($obj->getValidUntil(), "TestSample"); $this->assertEquals($obj->getLinks(), LinksTest::getObject()); }
// REST API is restricted in some countries. // API used: /v1/payments/payment require __DIR__ . '/../bootstrap.php'; use PayPal\Api\Amount; use PayPal\Api\Details; use PayPal\Api\FundingInstrument; use PayPal\Api\Item; use PayPal\Api\ItemList; use PayPal\Api\Payer; use PayPal\Api\Payment; use PayPal\Api\PaymentCard; use PayPal\Api\Transaction; // ### PaymentCard // A resource representing a payment card that can be // used to fund a payment. $card = new PaymentCard(); $card->setType("visa")->setNumber("4669424246660779")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setBillingCountry("US")->setLastName("Shopper"); // ### FundingInstrument // A resource representing a Payer's funding instrument. // For direct credit card payments, set the CreditCard // field on this object. $fi = new FundingInstrument(); $fi->setPaymentCard($card); // ### Payer // A resource representing a Payer that funds a payment // For direct credit card payments, set payment method // to 'credit_card' and add an array of funding instruments. $payer = new Payer(); $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi)); // ### Itemized information // (Optional) Lets you specify item wise