protected function initializePay($package, $user) { $payer = new \PayPal\Api\Payer(); $payer->setPaymentMethod('paypal'); $total = $package->price + $package->tax; $item = new \PayPal\Api\Item(); $item->setName($package->name)->setCurrency('USD')->setQuantity(1)->setPrice($package->price); $itemList = new \PayPal\Api\ItemList(); $itemList->setItems([$item]); $details = new \PayPal\Api\Details(); $details->setTax($package->tax)->setSubtotal($package->price); $amount = new \PayPal\Api\Amount(); $amount->setCurrency("USD")->setTotal($total)->setDetails($details); $transaction = new \PayPal\Api\Transaction(); $transaction->setAmount($amount)->setItemList($itemList)->setDescription($package->name)->setInvoiceNumber(uniqid()); $baseUrl = "http://trafficmonitor.ca/"; $redirectUrls = new \PayPal\Api\RedirectUrls(); $redirectUrls->setReturnUrl($baseUrl . "plan/success")->setCancelUrl($baseUrl . "packages"); $payment = new \PayPal\Api\Payment(); $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction)); try { $payment->create($this->paypal()); $transaction = new Transaction(array("user_id" => $user->id, "property" => "package", "property_id" => $package->id, "payment_id" => $payment->getId(), "amount" => $total)); $transaction->save(); } catch (Exception $e) { die($e); } return $approvalUrl = $payment->getApprovalLink(); }
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->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); $payment->setTransactions(array($transaction));