public function payDemo() { $this->authorize(); $addr = new Address(); $addr->setLine1('52 N Main ST'); $addr->setCity('Johnstown'); $addr->setCountryCode('US'); $addr->setPostalCode('43210'); $addr->setState('OH'); $card = new CreditCard(); $card->setNumber('4417119669820331'); $card->setType('visa'); $card->setExpireMonth('11'); $card->setExpireYear('2018'); $card->setCvv2('874'); $card->setFirstName('Joe'); $card->setLastName('Shopper'); $card->setBillingAddress($addr); $fi = new FundingInstrument(); $fi->setCreditCard($card); $payer = new Payer(); $payer->setPaymentMethod('credit_card'); $payer->setFundingInstruments(array($fi)); $amountDetails = new \PayPal\Api\Details(); $amountDetails->setSubtotal('7.41'); $amountDetails->setTax('0.03'); $amountDetails->setShipping('0.03'); $amount = new Amount(); $amount->setCurrency('USD'); $amount->setTotal('7.47'); $amount->setDetails($amountDetails); $transaction = new Transaction(); $transaction->setAmount($amount); $transaction->setDescription('This is the payment transaction description.'); $payment = new Payment(); $payment->setIntent('sale'); $payment->setPayer($payer); $payment->setTransactions(array($transaction)); $payment->create($this->_apiContext); }
$card = new \PayPal\Api\CreditCard(); $card->setNumber($_SESSION['cc_number']); $card->setType(strtolower($_SESSION['cc_type'])); $card->setExpireMonth($_SESSION['cc_exp_month']); $card->setExpireYear($_SESSION['cc_exp_year']); $card->setCvv2($_SESSION['cvv2']); $card->setFirstName($_SESSION['billing_first_name']); $card->setLastName($_SESSION['billing_last_name']); $card->setBillingAddress($addr); $fi = new \PayPal\Api\FundingInstrument(); $fi->setCreditCard($card); $payer = new \PayPal\Api\Payer(); $payer->setPaymentMethod('credit_card'); $payer->setFundingInstruments(array($fi)); $amountDetails = new \PayPal\Api\Details(); $amountDetails->setSubtotal(str_replace(",", "", number_format($_SESSION['subtotal'], 2))); $amountDetails->setTax(str_replace(",", "", number_format($_SESSION['tax_amount'], 2))); $amountDetails->setShipping(str_replace(",", "", number_format($_SESSION['shipping_amount'], 2))); $amountDetails->setHandlingFee(str_replace(",", "", number_format($_SESSION['handling_amount'], 2))); $amount = new \PayPal\Api\Amount(); $amount->setCurrency(isset($config['CurrencyCode']) ? $config['CurrencyCode'] : 'USD'); $amount->setTotal(str_replace(",", "", number_format($_SESSION['amount'], 2))); $amount->setDetails($amountDetails); $transaction = new \PayPal\Api\Transaction(); $transaction->setAmount($amount); $transaction->setDescription(isset($_SESSION['item_name']) && $_SESSION['item_name'] != '' ? $_SESSION['item_name'] : 'PayPal Payments Pro Virtual Terminal Sale'); $transaction->setInvoiceNumber($_SESSION['invoice']); $transaction->setCustom($_SESSION['notes']); $payment = new \PayPal\Api\Payment(); $payment->setIntent(strtolower($_SESSION['transaction_type'])); $payment->setPayer($payer);