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; // ### Create Payment // Create a payment by calling the payment->create() method // with a valid ApiContext (See bootstrap.php for more on `ApiContext`) // The return object contains the state. try { $payment->create($apiContext); } catch (Exception $ex) { // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printError('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $ex); exit(1); } // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY ResultPrinter::printResult('Authorize a Payment', 'Authorized Payment', $payment->getId(), $request, $payment); $transactions = $payment->getTransactions(); $relatedResources = $transactions[0]->getRelatedResources(); $authorization = $relatedResources[0]->getAuthorization(); return $authorization;