An item being paid for.
Inheritance: extends PayPal\Common\PayPalModel
Beispiel #1
0
 public function actionCheckout()
 {
     if ($postData = Yii::$app->request->post()) {
         $model = new Product();
         $order = new Order();
         $order->shipping_address = $postData['address'];
         $order->city = $postData['city'];
         $order->country = $postData['country'];
         $order->postal_code = $postData['postal_code'];
         $order->status = 0;
         $order->save();
         $order_id = $order->order_id;
         $items = [];
         foreach ($postData['qty'] as $key => $val) {
             $order_detail = new OrderDetail();
             $order_detail->order_id = $order_id;
             $order_detail->prod_id = $postData['prod_id'][$key];
             $order_detail->quantity = $postData['qty'][$key];
             $order_detail->unit_price = $postData['prod_price'][$key];
             $order_detail->unit_sum = $postData['prod_price'][$key] * $order_detail->quantity;
             $order_detail->save();
             $item = new Item();
             $item->setName($postData['prod_name'][$key])->setCurrency('USD')->setQuantity($val)->setPrice($postData['prod_price'][$key]);
             $items[] = $item;
         }
         $itemList = new ItemList();
         $itemList->setItems($items);
         $payment = preparePaypal($itemList);
         print_r($items);
     }
     exit;
 }
 /**
  * @return Payment
  * @throws CheckoutException
  */
 public function startPayment()
 {
     $total_amount = ($this->request->amount + $this->request->tax_amount - $this->request->discount_amount) * 100;
     $apiContext->setConfig(array('service.EndPoint' => "https://test-api.sandbox.paypal.com"));
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item1 = new Item();
     $item1->setName('Product1')->setCurrency('EUR')->setPrice(10.0)->setQuantity(2)->setTax(3.0);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     $details = new Details();
     $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
     $amount = new Amount();
     $amount->setCurrency('EUR')->setTotal(20)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment')->setInvoiceNumber('transactionid');
     $baseUrl = getBaseUrl();
     $redir = new RedirectUrls();
     $redir->setReturnUrl($baseUrl . '/');
     $redir->setCancelUrl($baseUrl . '/');
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redir)->setTransactions(array($transaction));
     $request = clone $payment;
     try {
         $payment->create($apiContext);
     } catch (\Exception $e) {
         throw new CheckoutException('Paypal error', 500, $e);
     }
     $approvalUrl = $payment->getApprovalLink();
     ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment);
     return $payment;
 }
Beispiel #3
0
function test()
{
    global $apiContext;
    // IncludeConfig('paypal/bootstrap.php');
    $payer = new Payer();
    $payer->setPaymentMethod("paypal");
    $item1 = new Item();
    $item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setPrice(7.5);
    $item2 = new Item();
    $item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setPrice(2);
    $itemList = new ItemList();
    $itemList->setItems(array($item1, $item2));
    $details = new Details();
    $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
    $amount = new Amount();
    $amount->setCurrency("USD")->setTotal(20)->setDetails($details);
    $transaction = new Transaction();
    $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
    $baseUrl = getBaseUrl();
    $redirectUrls = new RedirectUrls();
    $redirectUrls->setReturnUrl("{$baseUrl}/donate.php/execute_payment_test?success=true")->setCancelUrl("{$baseUrl}/donate.php/execute_payment_test?success=false");
    $payment = new Payment();
    $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
    $request = clone $payment;
    try {
        $payment->create($apiContext);
    } catch (Exception $ex) {
        ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
        exit(1);
    }
    $approvalUrl = $payment->getApprovalLink();
    ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='{$approvalUrl}' >{$approvalUrl}</a>", $request, $payment);
    return $payment;
}
Beispiel #4
0
 public function postPayment()
 {
     $data = array();
     if (is_array(Input::get('room_id'))) {
         foreach (Input::get('room_id') as $key => $val) {
             $data[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
         }
     }
     $data2 = array();
     if (is_array(Input::get('add_Am'))) {
         foreach (Input::get('add_Am') as $key => $val) {
             $data2[$key] = array('am_id' => Input::get('am_id.' . $key), 'rooms' => $val);
         }
     }
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $name = Input::get('packname');
     $price = Input::get('amount');
     $input_dFrom = Input::get('package_datefrom');
     $input_dTo = Input::get('package_dateto');
     $input_nPax = Input::get('num_pax');
     $input_fName = Input::get('fullN');
     $postData = new Reservation();
     $postData->dataInsertPost($name, $price, $input_dFrom, $input_dTo, $input_nPax, $input_fName, json_encode($data), 'PayPal', json_encode($data2));
     $item_1 = new Item();
     $item_1->setName($name)->setCurrency('PHP')->setQuantity('1')->setPrice(intval($price));
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('PHP')->setTotal(intval($price));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     //        $redirect_urls->setReturnUrl(URL::to('/dashboard/accommodation'))
     //            ->setCancelUrl(URL::to('/dashboard/accommodation'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $e) {
         echo $e->getData();
         // This will print a JSON which has specific details about the error.
         exit;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         return json_encode(['url' => $redirect_url]);
     }
     return Redirect::route('dashboard.packages.accommodation')->with('error', 'Unknown error occurred');
 }
 public function postPayment($producto_id)
 {
     $producto = Producto::find($producto_id);
     if (is_null($producto)) {
         App::abort(404);
     }
     $productoYaComprado = User::find(Auth::user()->id)->Productos()->whereProducto_id($producto->id)->first();
     if (!is_null($productoYaComprado)) {
         App::abort(404);
     }
     \Session::put('producto_id', $producto_id);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $currency = 'MXN';
     $item = new Item();
     $item->setName($producto->nombre)->setCurrency($currency)->setDescription($producto->nombre)->setQuantity(1)->setPrice($producto->precio);
     $items[] = $item;
     $subtotal += $producto->precio;
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal);
     //->setShipping(100);
     //$total = $subtotal + 100;
     $total = $subtotal;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             return \Redirect::route('home')->with('message', 'Algo salió mal, inténtalo de nuevo más tarde.');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('home')->with('message', 'Ups! Error desconocido. Inténtalo de nuevo más tarde.');
 }
Beispiel #6
0
 public function addProduct($description, $price, $quantity = 1)
 {
     $item = new Item();
     $item->setName($description)->setCurrency($this->currencyCode)->setQuantity($quantity)->setSku("123123")->setPrice($price);
     $this->itemList->addItem($item);
     $this->totalAmount += $price;
 }
Beispiel #7
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //        $item_1 = new Item();
     //        $item_1->setName('Item 1') // item name
     //            ->setCurrency('PHP')
     //            ->setQuantity('1')
     //            ->setPrice('0.01'); // unit price
     $package1 = Input::get('packname');
     $amount1 = Input::get('amount');
     $item_1 = new Item();
     $item_1->setName($package1)->setCurrency('PHP')->setQuantity('1')->setPrice($amount1);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('PHP')->setTotal($package1);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     //        try {
     //            $payment->create($this->_api_context);
     //        } catch (\PayPal\Exception\PPConnectionException $ex) {
     //
     //            if (\Config::get('app.debug')) {
     //                echo "Exception: " . $ex->getMessage() . PHP_EOL;
     //                $err_data = json_decode($ex->getData(), true);
     //                exit;
     //            } else {
     //                die('Some error occur, sorry for inconvenient');
     //            }
     //        }
     try {
         $payment->create($this->_api_context);
     } catch (PayPal\Exception\PayPalConnectionException $e) {
         echo $e->getData();
         // This will print a JSON which has specific details about the error.
         exit;
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
 public function actionPay($id)
 {
     $return = [];
     $total = 0;
     if (isset(Yii::$app->user->id)) {
         $user = User::findOne(Yii::$app->user->id);
         $race = Race::findOne($id);
         if ($user && $race) {
             /* paypal */
             $clientId = 'AYSq3RDGsmBLJE-otTkBtM-jBRd1TCQwFf9RGfwddNXWz0uFU9ztymylOhRS';
             $clientSecret = 'EGnHDxD_qRPdaLdZz8iCr8N7_MzF-YHPTkjs6NKYQvQSBngp4PTTVWkPZRbL';
             $apiContext = $this->getApiContext($clientId, $clientSecret);
             $payer = new Payer();
             $payer->setPaymentMethod("paypal");
             $total = $race->cost;
             $item1 = new Item();
             $item1->setName('Inscripción ' . $race->name)->setCurrency('USD')->setQuantity(1)->setPrice($total);
             /*$item1 = new Item();
               $item1->setName('Ground Coffee 40 oz')
                   ->setCurrency('USD')
                   ->setQuantity(1)
                   ->setPrice(7.5);
               $item2 = new Item();
               $item2->setName('Granola bars')
                   ->setCurrency('USD')
                   ->setQuantity(5)
                   ->setPrice(2);*/
             $itemList = new ItemList();
             $itemList->setItems(array($item1));
             $details = new Details();
             /*$details->setShipping(5)
               // ->setTax(1.3)
               ->setSubtotal($total);*/
             $details->setSubtotal($total);
             $amount = new Amount();
             $amount->setCurrency("USD")->setTotal($total)->setDetails($details);
             $transaction = new Transaction();
             $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Inscripción en Aurasur")->setInvoiceNumber('1234567890');
             $baseUrl = Url::base(true);
             $redirectUrls = new RedirectUrls();
             $redirectUrls->setReturnUrl($baseUrl . "/user/view?id=" . $user->id . "&r=ins")->setCancelUrl($baseUrl . "/race/pay?success=false&id=" . $id);
             $payment = new Payment();
             $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
             try {
                 $payment->create($apiContext);
             } catch (Exception $ex) {
                 print_r($ex);
                 exit(1);
             }
             $approvalUrl = $payment->getApprovalLink();
             /* --- */
         }
     } else {
         return $this->redirect(Yii::getAlias('@web') . '/site/login?ins=' . $id);
     }
     return $this->render('pay', ['race' => $race, 'aurl' => $approvalUrl]);
 }
Beispiel #9
0
 public function pay()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //agregar items de base de datos
     $items = array();
     $subtotal = 0;
     $productos = DB::table('carrito')->Join('producto', 'carrito.ItemCode', '=', 'producto.ItemCode')->where('carrito.user_id', Auth::user()->id)->get();
     //dd(Auth::user()->id);
     $currency = 'MXN';
     foreach ($productos as $key => $p) {
         $pIva = $p->precio * 0.16;
         $precioIva = $p->precio + $pIva;
         $item = new Item();
         $item->setName($p->ItemName)->setCurrency($currency)->setDescription($p->tipo)->setQuantity($p->cantidad)->setPrice($precioIva);
         $items[$key] = $item;
         $subtotal += $p->cantidad * $precioIva;
     }
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(100);
     $total = $subtotal + 100;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             return Redirect::route('carrito.failed');
             exit;
         } else {
             return Redirect::route('carrito.failed');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('carrito.failed');
 }
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $cart = \Session::get('cart');
     $currency = 'MXN';
     foreach ($cart as $producto) {
         $item = new Item();
         $item->setName($producto->name)->setCurrency($currency)->setDescription($producto->extract)->setQuantity($producto->quantity)->setPrice($producto->price);
         $items[] = $item;
         $subtotal += $producto->quantity * $producto->price;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     //costo de envio de la compra
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(100);
     //total de envio sumando el subtotal mas el envio
     $total = $subtotal + 100;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba con laravel para La Central Mueblera');
     //la ruta  para direccionar si se cancela o se envia conrectamente el pedido
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! Algo salió mal');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('cart-show')->with('error', 'Ups! Error desconocido.');
 }
Beispiel #11
0
 public static function preparePayment($payment, $domain)
 {
     $items = array();
     $currency = null;
     $total = 0;
     foreach ($payment->items as $item) {
         $tmpItem = new PayPalItem();
         $tmpItem->setName($item->description)->setCurrency($item->currency)->setQuantity($item->quantity)->setSku($item->sku)->setPrice($item->price);
         $items[] = $tmpItem;
         //
         $total += (double) $item->price;
         $currency = $item->currency;
     }
     $itemList = new ItemList();
     $itemList->setItems($items);
     $payer = new PayPalPayer();
     switch ($payment->payer->paymentMethod) {
         case Payer::PAYMENT_CREDIT_CARD:
             $payer->setPaymentMethod($payment->payer->paymentMethod);
             $card = new PayPalCreditCard();
             $card->setType($payment->payer->creditCard->type)->setNumber($payment->payer->creditCard->number)->setExpireMonth($payment->payer->creditCard->expireMonth)->setExpireYear($payment->payer->creditCard->expireYear)->setCvv2($payment->payer->creditCard->cvv2)->setFirstName($payment->payer->creditCard->firstName)->setLastName($payment->payer->creditCard->lastName);
             $fi = new FundingInstrument();
             $fi->setCreditCard($card);
             $payer->setFundingInstruments(array($fi));
             break;
         case Payer::PAYMENT_PAYPAL:
             $payer->setPaymentMethod($payment->payer->paymentMethod);
             break;
     }
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($payment->description);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($payment->returnUrl);
     $redirectUrls->setCancelUrl($payment->cancelUrl);
     $paypalPayment = new PayPalPayment();
     $paypalPayment->setRedirectUrls($redirectUrls);
     $paypalPayment->setIntent($payment->intent);
     $paypalPayment->setPayer($payer);
     $paypalPayment->setTransactions(array($transaction));
     try {
         $paypalPayment->create(static::getApiContext($domain));
         return static::getPayment($paypalPayment->getId(), $domain)->then(function ($payment) use($paypalPayment) {
             $payment->approvalUrl = static::getLink($paypalPayment->getLinks(), "approval_url");
             return $payment;
         });
     } catch (PayPalConnectionException $e) {
         return When::reject($e);
     } catch (PayPalInvalidCredentialException $e) {
         return When::reject($e);
     }
 }
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Item 1')->setCurrency('USD')->setQuantity(2)->setPrice('150');
     // unit price
     $item_2 = new Item();
     $item_2->setName('Item 2')->setCurrency('USD')->setQuantity(4)->setPrice('70');
     $item_3 = new Item();
     $item_3->setName('Item 3')->setCurrency('USD')->setQuantity(1)->setPrice('20');
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1, $item_2, $item_3));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal(580);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
         //            echo'hello';
         //            print_r($test);die;
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     if (is_array($payment->getLinks()) || is_object($payment->getLinks())) {
         foreach ($payment->getLinks() as $link) {
             echo 'reached';
             if ($link->getRel() == 'approval_url') {
                 $redirect_url = $link->getHref();
                 break;
             }
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     dd(Session::all());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Beispiel #13
0
 public function postPayment()
 {
     $name = 'Transaction';
     /*$mmnumber      = Input::get('number');
       $amounttosend     = Input::get('amount');
       $currency   = Input::get('currency');*/
     $mmnumber = Input::get('number');
     $amounttosend = Input::get('amount');
     $currency = Input::get('currency');
     $charges = new PlatformCharges($amounttosend, $currency);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Transaction')->setCurrency('USD')->setQuantity(1)->setPrice((int) $charges->getDueAmountForPayPalToMobileMoney());
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal((int) $charges->getDueAmountForPayPalToMobileMoney());
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Send money To a Mobile Money User');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment-status'))->setCancelUrl(URL::route('payment-status'));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occurred, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return "Error!!!!";
     /*Redirect::route('original.route')
       ->with('error', 'Unknown error occurred'); */
 }
Beispiel #14
0
function CreateItem($itemDetails)
{
    $item = new Item();
    foreach ($GLOBALS['META_DATA']['item'] as $meta) {
        if (isset($itemDetails[$meta])) {
            $item->{'set' . str_replace('_', '', $meta)}($itemDetails[$meta]);
        }
    }
    // defaults
    $item->setCurrency($GLOBALS['PAYPAL']['currency']);
    return $item;
}
Beispiel #15
0
 public function postBuy(Request $request)
 {
     $data = $request->all();
     $customer = $this->customer->getByToken();
     $shopping_cart = $this->cart->getByToken();
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $paypal_items = [];
     $total = 0;
     foreach ($shopping_cart->shopping_cart_products as $shopping_cart_product) {
         $item = new Item();
         $item->setName($shopping_cart_product->product_collection_name . " // " . $shopping_cart_product->product_variant_name . " // " . $shopping_cart_product->product_color_name)->setCurrency(config('shop.default_currency'))->setQuantity($shopping_cart_product->quantity)->setPrice($shopping_cart_product->price_brut / 100);
         array_push($paypal_items, $item);
         $total += $shopping_cart_product->price_brut / 100 * $shopping_cart_product->quantity;
     }
     $subtotal = $total;
     $total += config('shop.default_shipping_cost') / 100;
     $item_list = new ItemList();
     $item_list->setItems($paypal_items);
     $details = new Details();
     $details->setShipping(config('shop.default_shipping_cost') / 100)->setSubtotal($subtotal);
     $amount = new Amount();
     $amount->setCurrency(config('shop.default_currency'))->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Einkauf bei ZWEI :: Taschen');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(url(config('app.locale') . '/paypal/thankyou'))->setCancelUrl(url(config('app.locale') . '/paypal/cancellation'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (config('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die(trans('shop.some_error_occurred'));
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     $this->cart->update(['id' => $shopping_cart->id, 'paypal_payment_id' => $payment->getId(), 'remarks' => $data['remarks'], 'customer_id' => $customer->id]);
     if (isset($redirect_url)) {
         return redirect($redirect_url);
     }
     return redirect()->route(config('app.locale') . '/feedback/paypal-error')->with('error', trans('shop.some_error_occurred'));
 }
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $cart = \Session::get('product');
     $currency = 'USD';
     $item = new Item();
     $item->setName($cart->name)->setCurrency($currency)->setDescription($cart->description)->setQuantity(1)->setPrice($cart->price);
     $items[] = $item;
     $subtotal += $cart->price;
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping(0);
     $total = $subtotal + 0;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Order plan in hdsports.in');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! something went wrong');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::to('/')->with('message', 'Ups! Unknown mistake.');
 }
Beispiel #17
0
 private function createPayment($details)
 {
     $payment = new Payment();
     $payer = new Payer();
     $payer->payment_method = "paypal";
     $amount = new Amount();
     $amount->currency = $details['PAYMENTREQUEST_CURRENCYCODE'];
     $amount->total = $details['PAYMENTREQUEST_AMT'];
     $transaction = new Transaction();
     $transaction->amount = $amount;
     $transaction->description = $details['PAYMENTREQUEST_DESCRIPTION'];
     $itemList = new ItemList();
     foreach ($details['PAYMENTREQUEST_ITEMS'] as $itemInfo) {
         $item = new Item();
         $item->setQuantity($itemInfo['quantity']);
         $item->setName($itemInfo['name']);
         $item->setDescription($itemInfo['description']);
         $item->setPrice($itemInfo['price']);
         $item->setCategory($itemInfo['category']);
         $item->setCurrency($itemInfo['currency']);
         $item->setTax($itemInfo['tax']);
         $item->setSku($itemInfo['sku']);
         $itemList->addItem($item);
     }
     $addressInfo = $details['PAYMENTREQUEST_SHIPPING_ADDRESS'];
     $shippingAddress = new ShippingAddress();
     $shippingAddress->setRecipientName($addressInfo['recipient_name']);
     $shippingAddress->setLine1($addressInfo['line1']);
     $shippingAddress->setPostalCode($addressInfo['postal_code']);
     $shippingAddress->setCity($addressInfo['city']);
     $shippingAddress->setCountryCode($addressInfo['country_code']);
     $itemList->setShippingAddress($shippingAddress);
     $transaction->setItemList($itemList);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->return_url = $details['RETURN_URL'];
     $redirectUrls->cancel_url = $details['CANCEL_URL'];
     $payment->intent = "sale";
     $payment->payer = $payer;
     $payment->redirect_urls = $redirectUrls;
     $payment->transactions = [$transaction];
     if (false == isset($details['response']) && false == isset($details['response']['state']) && isset($payment->payer->payment_method) && 'paypal' == $payment->payer->payment_method) {
         $paymentResponse = $payment->create($this->api);
         $details->replace(['response' => $paymentResponse->toArray()]);
         foreach ($paymentResponse->links as $link) {
             if ($link->rel == 'approval_url') {
                 $details->replace(['approval_url' => $link->href]);
             }
         }
     }
 }
Beispiel #18
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $cart = \Session::get('cart');
     $currency = 'USD';
     foreach ($cart as $producto) {
         $item = new Item();
         $item->setName($producto->tipograno)->setCurrency($currency)->setDescription($producto->descripcion)->setQuantity($producto->cantidad)->setPrice($producto->precio);
         $items[] = $item;
         $subtotal += $producto->cantidad * $producto->precio;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $total = $subtotal;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba en Agricola Grain App');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Ups! Algo salió mal');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('cart-show')->with('error', 'Ups! Error desconocido.');
 }
 /**
  * Add item to list
  *
  * @param array $itemData Array item data
  * @return self
  */
 public function setItem($itemData)
 {
     // Check parameter is single or multiple dimensional
     if (count($itemData) === count($itemData, COUNT_RECURSIVE)) {
         $itemData = [$itemData];
     }
     foreach ($itemData as $data) {
         $item = new Item();
         $item->setName($data['name'])->setCurrency($this->paymentCurrency)->setSku($data['sku'])->setQuantity($data['quantity'])->setPrice($data['price']);
         $this->itemList[] = $item;
         $this->totalAmount += $data['price'] * $data['quantity'];
     }
     return $this;
 }
 public function pay()
 {
     #dd(Input::all());
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $counter = 0;
     $items = [];
     foreach (Input::all() as $input) {
         if (Input::has('item_name' . $counter)) {
             $item = new Item();
             $item->setName(Input::get('item_name' . $counter))->setCurrency('EUR')->setQuantity(Input::get('item_qtt' . $counter))->setPrice(Input::get('item_price' . $counter));
             $items[] = $item;
         }
         $counter++;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $amount = new Amount();
     $amount->setCurrency('EUR')->setTotal(Input::get('total'));
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('This is just a demo transaction');
     $redirect_url = new RedirectUrls();
     $redirect_url->setReturnUrl(URL::route('paymentStatus'))->setCancelUrl(URL::route('paymentStatus'));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirect_url)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Beispiel #21
0
 public function postPayment()
 {
     // echo '123123';exit;
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $total = Input::get('total');
     $qty = Input::get('qty');
     $price = Input::get('price');
     $bill_id = Input::get('bill_id');
     $item_1 = new Item();
     $item_1->setName(Input::get('service_name'))->setCurrency('USD')->setQuantity($qty)->setPrice($price);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Your transaction description');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     Session::put('bill_id', $bill_id);
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Beispiel #22
0
 public static function createPayPal($invoiceNumber, \PropelPDO $con)
 {
     $i18n = Localizer::get('payment');
     // ### 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("paypal");
     // ### Itemized information
     // (Optional) Lets you specify item wise
     // information
     $item1 = new Item();
     $item1->setName($i18n['item_name'])->setDescription($i18n['item_description'])->setCurrency(TransactionEntity::$BASE_CURRENCY)->setQuantity(1)->setTax(0)->setPrice(TransactionEntity::$MEMBER_FEE);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     $amount = new Amount();
     $amount->setCurrency(TransactionEntity::$BASE_CURRENCY)->setTotal(TransactionEntity::$MEMBER_FEE);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it.
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($i18n['transaction_description'])->setInvoiceNumber($invoiceNumber);
     // ### Redirect urls
     // Set the urls that the buyer must be redirected to after
     // payment approval/ cancellation.
     $success = Router::toModule('account', 'index');
     $failure = Router::toModule('guide', 'index', ['purchase_failed' => true]);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($success)->setCancelUrl($failure);
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent set to sale 'sale'
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setExperienceProfileId(self::getPaymentExperienceProfileId())->setTransactions(array($transaction));
     // ### 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.
     $apiContext = self::getApiContext();
     $payment->create($apiContext);
     return $payment;
 }
 public function postPayment()
 {
     $input_amount = \Input::get('amount');
     $input_user_id = \Input::get('user_id');
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Υπηρεσίες freelancing')->setCurrency('EUR')->setQuantity(1)->setPrice($input_amount);
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('EUR')->setTotal($input_amount);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Ειμαι η περιγραφή');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(\URL::route('payment.status'))->setCancelUrl(\URL::route('payment'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setId("2014031400023")->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     \Session::put('paypal_payment_id', $payment->getId());
     \Session::put('user_id', $input_user_id);
     \Session::put('amount', $input_amount);
     if (isset($redirect_url)) {
         // redirect to paypal
         return \Redirect::away($redirect_url);
     }
     return \Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Beispiel #24
0
 public function postPayment(Request $request)
 {
     foreach ($request->get('passengername') as $key => $name) {
         $passenger = Passenger::create(['reservation_id' => $request->reservation_id, 'cruise_id' => $request->cruise_id, 'name' => $name, 'identification' => $request->get('passengeridentification')[$key], 'nationality' => $request->get('passengernationality')[$key], 'contact_no' => $request->get('passengercontact')[$key], 'gender' => $request->get('passengergender')[$key]]);
     }
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName($request->cruise_name)->setCurrency('MYR')->setQuantity(1)->setPrice($request->total);
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('MYR')->setTotal($request->total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription($request->description);
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('payment.status'))->setCancelUrl(URL::route('payment.status'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occur, sorry for inconvenient');
         }
     }
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirect_url = $link->getHref();
             break;
         }
     }
     // add payment ID to session
     Session::put('paypal_payment_id', $payment->getId());
     Session::put('reservation_id', $request->reservation_id);
     if (isset($redirect_url)) {
         // redirect to paypal
         return Redirect::away($redirect_url);
     }
     return Redirect::route('original.route')->with('error', 'Unknown error occurred');
 }
Beispiel #25
0
 public function start()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $itemList = new ItemList();
     $productsSum = 0.0;
     foreach ($this->order->getProducts() as $product) {
         $item = new Item();
         $item->setName($product->getName())->setCurrency($this->order->getCurrency())->setQuantity($product->getQuantity())->setSku($product->getSku())->setPrice($product->getPrice());
         $itemList->addItem($item);
         $productsSum += $product->getTotal();
     }
     $details = new Details();
     $details->setSubtotal($productsSum);
     $total = $productsSum;
     if ($delivery = $this->order->getDelivery()) {
         $details->setShipping($delivery);
         $total += $delivery;
     }
     if ($vat = $this->order->getVat()) {
         $details->setTax($vat);
         $total += $vat;
     }
     $amount = new Amount();
     $amount->setCurrency($this->order->getCurrency())->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($this->order->getDescription())->setInvoiceNumber(uniqid());
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl(env('DOMAIN') . url($this->config['url_return'], ['paypalRest', $this->order->getOrder()]))->setCancelUrl(env('DOMAIN') . url($this->config['url_cancel'], ['paypalRest', $this->order->getOrder()]));
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
     try {
         $this->log($payment);
         $payment->create($this->paypal);
         $this->log($payment);
     } catch (\Exception $e) {
         $this->log($e);
         throw $e;
     } finally {
         redirect()->away($payment->getApprovalLink())->send();
     }
 }
 public function getPayTaskUrl($task)
 {
     $apiContext = $this->apiContext;
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $item1 = new Item();
     $item1->setName($task->title)->setCurrency($this->currency)->setQuantity(1)->setSku($task->id)->setPrice($task->total);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     $amount = new Amount();
     $amount->setCurrency($this->currency)->setTotal($task->total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment for " . $task->title)->setInvoiceNumber($task->id . '_' . date('YmdHis'));
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($this->redirectSuccess . '/' . $task->id)->setCancelUrl($this->redirectFail . '/' . $task->id);
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     $payment->create($apiContext);
     $this->storePaymentSession($payment->getId(), $task->id);
     return $payment->getApprovalLink();
 }
Beispiel #27
0
 /**
  * @param string $name
  * @param int $currency
  * @param int $quantity
  * @param string $sku
  * @param int $price
  * @return Item
  */
 public static function createItem($name, $currency, $quantity, $sku, $price)
 {
     $item = new Item();
     $item->setName($name);
     $item->setCurrency($currency);
     $item->setQuantity($quantity);
     $item->setSku($sku);
     $item->setPrice($price);
     return $item;
 }
 /**
  * @return array array of PayPal\Api\Transaction
  */
 protected function getTransactions()
 {
     $payPalItems = array();
     $currency = $this->currency ? $this->currency : $this->context->getCurrency();
     $payPalItem = new Item();
     $payPalItem->setName($this->name);
     $payPalItem->setCurrency($currency);
     $payPalItem->setQuantity($this->quantity);
     $payPalItem->setPrice($this->price);
     $payPalItems[] = $payPalItem;
     $totalPrice = $this->quantity * $this->price;
     $itemLists = new ItemList();
     $itemLists->setItems($payPalItems);
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($totalPrice);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setItemList($itemLists);
     return array($transaction);
 }
Beispiel #29
-1
 public function order()
 {
     $paypalConf = $this->config->item('paypal');
     $clientId = $paypalConf['clientId'];
     $clientSecret = $paypalConf['clientSecret'];
     $appName = $paypalConf['appName'];
     $price = $paypalConf['price'];
     $shiping = 0;
     $tax = 0;
     $mode = "sandbox";
     //or live
     $apiContext = new ApiContext(new OAuthTokenCredential($clientId, $clientSecret));
     $apiContext->setConfig(array('mode' => $mode, 'log.LogEnabled' => false));
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $item1 = new Item();
     $item1->setName($appName)->setCurrency('USD')->setQuantity(1)->setPrice($price);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     $details = new Details();
     $details->setShipping($shiping)->setTax($tax)->setSubtotal($price);
     $amount = new Amount();
     $amount->setCurrency("USD")->setTotal($price + $shiping + $tax)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
     $token = $this->createToken();
     $baseUrl = getBaseUrl();
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl("{$baseUrl}/paypal/ordersucess?success=true&tk1=" . $token[0] . "&tk2=" . $token[1])->setCancelUrl("{$baseUrl}/paypal/orderfailed?success=false");
     $payment = new Payment();
     $payment->setIntent("order")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     // For Sample Purposes Only.
     $request = clone $payment;
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
         ResultPrinter::printError("Created Payment Order Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
         exit(1);
     }
     $approvalUrl = $payment->getApprovalLink();
     header("Location: " . $approvalUrl . "");
     die;
 }
Beispiel #30
-3
 public function credit_card()
 {
     return "Hello?";
     $card = new CreditCard();
     $card->setType("visa")->setNumber("4148529247832259")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     $item1 = new Item();
     $item1->setName('Ground Coffee 40 oz')->setDescription('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setTax(0.3)->setPrice(7.5);
     $item2 = new Item();
     $item2->setName('Granola bars')->setDescription('Granola Bars with Peanuts')->setCurrency('USD')->setQuantity(5)->setTax(0.2)->setPrice(2);
     $itemList = new ItemList();
     $itemList->setItems(array($item1, $item2));
     $details = new Details();
     $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
     $amount = new Amount();
     $amount->setCurrency("USD")->setTotal(20)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
     $request = clone $payment;
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using <a href="https://ppmts.custhelp.com/app/answers/detail/a_id/750">Step 4, on this link</a>, and using it.', 'Payment', null, $request, $ex);
         exit(1);
     }
     ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
     return $payment;
 }