Additional details of the payment amount.
Наследование: extends PayPal\Common\PayPalModel
Пример #1
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;
}
 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.');
 }
Пример #3
0
 public function success()
 {
     $paymentId = request('paymentId');
     $payment = Payment::get($paymentId, $this->paypal);
     $execution = new PaymentExecution();
     $execution->setPayerId(request('PayerID'));
     $transaction = new Transaction();
     $amount = new Amount();
     $details = new Details();
     $productsSum = 0.0;
     foreach ($this->order->getProducts() as $product) {
         $productsSum += $product->getTotal();
     }
     $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->setCurrency($this->order->getCurrency())->setTotal($total)->setDetails($details);
     $transaction->setAmount($amount);
     $execution->addTransaction($transaction);
     try {
         $payment->execute($execution, $this->paypal);
     } catch (\Exception $e) {
         $this->log($e);
         throw $e;
     } finally {
         Payment::get($paymentId, $this->paypal);
     }
 }
Пример #4
0
 public function testSerializeDeserialize()
 {
     $a1 = $this->amountDetails;
     $a2 = new Details();
     $a2->fromJson($a1->toJson());
     $this->assertEquals($a1, $a2);
 }
 /**
  * @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;
 }
Пример #6
0
 /**
  * @param float $shippingPrice
  * @param float $taxPrice
  * @param float $subtotal
  *
  * @return Details
  */
 public static function createDetails($shippingPrice, $taxPrice, $subtotal)
 {
     $details = new Details();
     $details->setShipping($shippingPrice);
     $details->setTax($taxPrice);
     $details->setSubtotal($subtotal);
     return $details;
 }
Пример #7
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.');
 }
Пример #9
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'));
 }
Пример #10
0
 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.');
 }
Пример #11
0
 /**
  * @depends testSerializationDeserialization
  * @param Details $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getSubtotal(), "12.34");
     $this->assertEquals($obj->getShipping(), "12.34");
     $this->assertEquals($obj->getTax(), "12.34");
     $this->assertEquals($obj->getHandlingFee(), "12.34");
     $this->assertEquals($obj->getShippingDiscount(), "12.34");
     $this->assertEquals($obj->getInsurance(), "12.34");
     $this->assertEquals($obj->getGiftWrap(), "12.34");
     $this->assertEquals($obj->getFee(), "12.34");
 }
Пример #12
0
 /**
  * Cria o pagamento Paypal: passos 2/3
  *
  * @access	public
  * @param	
  * @return	error string
  */
 public function create_payment($items_array, $details_array)
 {
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // define os items
     $i = 0;
     foreach ($items_array as $item) {
         $items[$i] = new Item();
         $items[$i]->setName($item['name'])->setCurrency(PAYPAL_CURRENCY)->setQuantity($item['quantity'])->setPrice($item['price']);
         $i++;
     }
     $itemList = new ItemList();
     $itemList->setItems($items);
     // Define os totais
     $details = new Details();
     $details->setShipping($details_array['shipping'])->setTax($details_array['tax'])->setSubtotal($details_array['subtotal']);
     // Define a quantidade
     $amount = new Amount();
     $amount->setCurrency(PAYPAL_CURRENCY)->setTotal($details_array['total'])->setDetails($details);
     // cria a transação
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("");
     // cria o URL
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl(SITE_PATH . "success.php")->setCancelUrl(SITE_PATH . "cart.php");
     // cria o pagamento
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($this->api_context);
     } catch (PayPal\Exception\PPConnectionException $ex) {
         return $ex->getMessage();
     }
     // busca o URL de redirecionamento
     foreach ($payment->getLinks() as $link) {
         if ($link->getRel() == 'approval_url') {
             $redirectUrl = $link->getHref();
             break;
         }
     }
     // redireciona
     $_SESSION['payment_id'] = $payment->getId();
     if (isset($redirectUrl)) {
         header("Location: {$redirectUrl}");
         exit;
     }
 }
Пример #13
0
 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]);
 }
 /**
  * Called by shop to charge order's amount.
  *
  * @param Cart $cart Cart.
  *
  * @return bool
  */
 public function onCharge($order)
 {
     $this->statusCode = 'pending';
     // Begin paypal
     try {
         if ($order->total <= 0) {
             $this->statusCode = 'completed';
             $this->detail = 'Order total is 0; no PayPal transaction required.';
             $this->transactionId = uniqid();
             return true;
         }
         $this->setContext();
         $payer = new Payer();
         $payer->setPaymentMethod('paypal');
         $list = new ItemList();
         $list->setItems($this->toPayPalItems($order));
         $details = new Details();
         $details->setShipping($order->totalShipping)->setTax($order->totalTax)->setSubtotal($order->totalPrice);
         $amount = new Amount();
         $amount->setCurrency(Config::get('shop.currency'))->setTotal($order->total)->setDetails($details);
         $transaction = new Transaction();
         $transaction->setAmount($amount)->setItemList($list)->setDescription(sprintf('%s payment, Order #%d', Config::get('shop.name'), $order->id))->setInvoiceNumber($order->id);
         $redirectUrls = new RedirectUrls();
         $redirectUrls->setReturnUrl($this->callbackSuccess)->setCancelUrl($this->callbackFail);
         $payment = new Payment();
         $payment->setIntent('sale')->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions([$transaction]);
         //$request = clone $payment;
         $payment->create($this->apiContext);
         $this->approvalUrl = $payment->getApprovalLink();
         $this->detail = sprintf('Pending approval: %s', $this->approvalUrl);
         return true;
     } catch (PayPalConnectionException $e) {
         $response = json_decode($e->getData());
         throw new GatewayException(sprintf('%s: %s', $response->name, isset($response->message) ? $response->message : 'Paypal payment Failed.'), 1001, $e);
     } catch (\Exception $e) {
         throw new GatewayException($e->getMessage(), 1000, $e);
     }
     return false;
 }
Пример #15
0
 public function process($orderData, $cartProducts = [])
 {
     $this->setApiContext();
     $this->_apiContext->setConfig(['mode' => Configuration::getConfiguration('paypal_payment_mode'), 'service.EndPoint' => Configuration::getConfiguration('paypal_payment_url'), 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => Configuration::getConfiguration('paypal_payment_log'), 'log.FileName' => storage_path('logs/paypal.log'), 'log.LogLevel' => 'FINE']);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $itemList = new ItemList();
     $subTotal = 0;
     $taxTotal = 0;
     foreach ($cartProducts as $product) {
         $item = new Item();
         $model = $product['model'];
         $item->setName($model->title)->setCurrency('USD')->setQuantity($product['qty'])->setSku($model->sku)->setPrice($product['price']);
         $itemList->addItem($item);
         $subTotal += $product['price'] * $product['qty'];
         $taxTotal += $product['tax_amount'] * $product['qty'];
     }
     $total = $subTotal + $taxTotal;
     $shippingOption = $orderData['shipping_method'];
     $shipping = Shipping::get($shippingOption);
     $details = new Details();
     $details->setShipping($shipping->getAmount())->setTax($taxTotal)->setSubtotal($subTotal);
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription('Payment description')->setInvoiceNumber(uniqid());
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl(route('paypal.store'));
     $redirectUrls->setCancelUrl(route('paypal.cancel'));
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions([$transaction]);
     $response = $payment->create($this->_apiContext);
     $redirectUrl = $response->links[1]->href;
     return $redirectUrl;
 }
Пример #16
0
 public function sendRequest()
 {
     $details = new Details();
     $details->setShipping(0)->setTax(0)->setSubtotal($this->totalAmount);
     $amount = new Amount();
     $amount->setCurrency($this->currencyCode)->setTotal($this->totalAmount)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($this->itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
     $baseUrl = 'http://localhost/';
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl("{$baseUrl}/ExecutePayment.php?success=true")->setCancelUrl("{$baseUrl}/ExecutePayment.php?success=false");
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($this->payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($this->apiContext);
     } catch (Exception $ex) {
         // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
         var_dump($ex);
         exit(1);
     }
     $approvalUrl = $payment->getApprovalLink();
     header('Location: ' . $approvalUrl);
     quit();
 }
Пример #17
0
 public function postPayment($type)
 {
     \Session::forget('pagos_id');
     $pagos_id = \Session::get('pagos_id');
     //\Session::put('pagos_id', $pagos_id);
     \Session::forget('pagos_data');
     $pagos_data = \Session::get('pagos_data');
     //\Session::put('pagos_data', $pagos_data);
     $user_id = $this->auth->user()->id;
     $month = array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
     $cta = $this->auth->user()->type;
     $cuota = Cuotas::find($cta);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     $subtotal = 0;
     $currency = 'MXN';
     $price = $cuota->amount;
     $descuento = false;
     $discount = -$price;
     $qty = 1;
     $shipp = 0;
     $items_arr = array();
     $pago_hasta = 0;
     $lmt = 0;
     $m = 1;
     //mes de inicio 1-12
     $y = 2016;
     //año de inicio
     $d = date('d');
     $ultimo_p = DB::table('pagos')->where('id_user', $this->auth->user()->id)->where('status', 1)->orderBy('date', 'dsc')->get();
     foreach ($ultimo_p as $pay) {
         $pago_hasta = explode("-", $pay->date);
         $m = intval($pago_hasta[1]);
         $y = intval($pago_hasta[0]);
         $m++;
         if ($m == 13) {
             $m = 1;
             $y++;
         }
         break;
     }
     $prueba = '';
     // 1-mensual
     // 2-semestral
     // 3-anual
     // 4-saldo vencido
     if ($type == 1) {
         $lmt = 1;
     } else {
         if ($type == 2) {
             $lmt = 6;
         } else {
             if ($type == 3) {
                 $lmt = 12;
                 $descuento = true;
             } else {
                 if ($type == 4) {
                     $vencidos = DB::table('pagos')->where('id_user', $this->auth->user()->id)->where('status', 0)->orderBy('date', 'asc')->get();
                     $vence_date = explode("-", $vencidos[0]->date);
                     $m = intval($vence_date[1]);
                     $y = intval($vence_date[0]);
                     //[0]2014 [1]mes [2]dia
                     foreach ($vencidos as $vence) {
                         $pagos_id[] = $vence->id;
                         \Session::put('pagos_id', $pagos_id);
                         $lmt++;
                     }
                 }
             }
         }
     }
     //populate items array
     for ($i = 0; $i < $lmt; $i++) {
         $items_arr[$i] = $month[$m - 1] . " " . $y;
         //se llena con fechas -> yyyy-mm-dd
         if ($m < 10) {
             $pagos_data[$i] = $y . '-0' . $m . '-' . $d;
             \Session::put('pagos_data', $pagos_data);
         } else {
             $pagos_data[$i] = $y . '-' . $m . '-' . $d;
             \Session::put('pagos_data', $pagos_data);
         }
         $m++;
         if ($m == 13) {
             $m = 1;
             $y++;
         }
     }
     //crear los items
     foreach ($items_arr as $pago) {
         $item = new Item();
         $item->setName($pago)->setCurrency($currency)->setDescription('item description')->setQuantity($qty)->setPrice($price);
         $items[] = $item;
         $subtotal += $price * $qty;
     }
     //descuento
     if ($descuento) {
         $item = new Item();
         $item->setName('Descuento Pago Anual(1 mes)')->setCurrency($currency)->setDescription('item description')->setQuantity($qty)->setPrice($discount);
         $items[] = $item;
         $subtotal += $discount * $qty;
     }
     $item_list = new ItemList();
     $item_list->setItems($items);
     $details = new Details();
     $details->setSubtotal($subtotal)->setShipping($shipp);
     $total = $subtotal + $shipp;
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Pedido de prueba en mi Laravel 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\PayPalConnectionException $ex) {
     		    //echo $ex->getCode(); // Prints the Error Code
     		    //echo $ex->getData(); // Prints the detailed error message 
     		    die($ex);
     		} catch (Exception $ex) {
     		    die($ex);
     		}
     */
     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()->to('micuenta')->with('error', 'Ha ocurrido un error. Volver a intentar.');
 }
 private function pagoPaypal($id_participante, $id_evento, $costo_evento, $total_asistencia, $tipo_asistencia)
 {
     $precio = $costo_evento * $total_asistencia;
     $setTax = 0;
     $setShipping = 0;
     $apiContext = new ApiContext(new OAuthTokenCredential("AZ3IGQMWrIJfatlyB2q31xGf6DyNwuPdhO1Pq5gHaOtNEbv9kfVXBTZdYfrW1Md5D44HenTCFZhAh1jq", "ECeakgz-CnwYFIYspPmmwYri92RGJcV5As7EoH1kZbMyGg47BRRyOIGz0y3qlr2W0pBDNKXw9R7ADDOq"));
     $apiContext->setConfig(array('mode' => 'sandbox', 'log.LogEnabled' => false, 'log.FileName' => PATH_SITE . "public/PayPal.log", 'log.LogLevel' => 'DEBUG', 'validation.level' => 'log'));
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $item1 = new Item();
     $item1->setName("Asistencia a evento")->setCurrency('MXN')->setQuantity(1)->setPrice($precio);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     $details = new Details();
     $details->setShipping($setShipping)->setTax($setTax)->setSubtotal($precio);
     $total = $precio + $setShipping + $setTax;
     $amount = new Amount();
     $amount->setCurrency("MXN")->setTotal($total)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("PAGO POR ASISTIR A EVENTO")->setInvoiceNumber(uniqid());
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl(PATH_SITE . "success/?id_participante=" . $id_participante . "&id_evento=" . $id_evento . "&precio=" . $precio . "&tipo=" . $tipo_asistencia)->setCancelUrl(PATH_SITE . "cancel/");
     $payment = new Payment();
     $payment->setIntent("order")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($apiContext);
         $approvalUrl = $payment->getApprovalLink();
         header("Location: " . $approvalUrl);
     } catch (Exception $ex) {
         echo $ex->getMessage();
         $this->cargarVista("ERROR AL PROCESAR EL PAGO.", "danger", "fa fa-thumbs-o-down");
     }
 }
Пример #19
0
$payer = new Payer();
$payer->setPaymentMethod("paypal");
// ### Itemized information
// (Optional) Lets you specify item wise
// information
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setSku("123123")->setPrice(7.5);
$item2 = new Item();
$item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setSku("321321")->setPrice(2);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency("USD")->setTotal(20)->setDetails($details);
// ### 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("Payment description")->setInvoiceNumber(uniqid());
// ### Redirect urls
// Set the urls that the buyer must be redirected to after
Пример #20
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $_contentCart = Cart::instance('shopping')->content();
     $_itemsCount = Cart::instance('shopping')->count();
     $_arryItems = array();
     $_i = 0;
     foreach ($_contentCart as $row) {
         if ($_i < $_itemsCount) {
             $item = new Item();
             $item->setName($row->name)->setDescription($row->name)->setCurrency('USD')->setQuantity((double) $row->qty)->setTax((double) ($row->price * 10) / 100)->setPrice((double) $row->price);
             //$435.00
             $_arryItems[$_i] = $item;
             $_i++;
         }
     }
     $item_list = new ItemList();
     $item_list->setItems(array($_arryItems));
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($_arryItems);
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $details = new Details();
     $details->setShipping("0")->setTax((string) (Cart::instance('shopping')->total() * 10) / 100)->setSubtotal((string) Cart::instance('shopping')->total());
     $amount = new Amount();
     $amount->setCurrency("USD")->setTotal((string) Cart::instance('shopping')->total() + Cart::instance('shopping')->total() * 10 / 100)->setDetails($details);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $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\PayPalConnectionException $ex) {
         echo $ex->getCode();
         // Prints the Error Code
         echo $ex->getData();
         // Prints the detailed error message
         die($ex);
     } catch (Exception $ex) {
         die($ex);
     }
     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 View::make('pages.home');
 }
 function get_approvalurl()
 {
     try {
         // try a payment request
         $PaymentData = AngellEYE_Gateway_Paypal::calculate(null, $this->send_items);
         $OrderItems = array();
         if ($this->send_items) {
             foreach ($PaymentData['order_items'] as $item) {
                 $_item = new Item();
                 $_item->setName($item['name'])->setCurrency(get_woocommerce_currency())->setQuantity($item['qty'])->setPrice($item['amt']);
                 array_push($OrderItems, $_item);
             }
         }
         $redirectUrls = new RedirectUrls();
         $redirectUrls->setReturnUrl(add_query_arg(array('pp_action' => 'executepay'), home_url()));
         $redirectUrls->setCancelUrl($this->cancel_url);
         $payer = new Payer();
         $payer->setPaymentMethod("paypal");
         $details = new Details();
         if (isset($PaymentData['shippingamt'])) {
             $details->setShipping($PaymentData['shippingamt']);
         }
         if (isset($PaymentData['taxamt'])) {
             $details->setTax($PaymentData['taxamt']);
         }
         $details->setSubtotal($PaymentData['itemamt']);
         $amount = new Amount();
         $amount->setCurrency(PP_CURRENCY);
         $amount->setTotal(WC()->cart->total);
         $amount->setDetails($details);
         $items = new ItemList();
         $items->setItems($OrderItems);
         $transaction = new Transaction();
         $transaction->setAmount($amount);
         $transaction->setDescription('');
         $transaction->setItemList($items);
         //$transaction->setInvoiceNumber($this->invoice_prefix.$order_id);
         $payment = new Payment();
         $payment->setRedirectUrls($redirectUrls);
         $payment->setIntent("sale");
         $payment->setPayer($payer);
         $payment->setTransactions(array($transaction));
         $payment->create($this->getAuth());
         $this->add_log(print_r($payment, true));
         //if payment method was PayPal, we need to redirect user to PayPal approval URL
         if ($payment->state == "created" && $payment->payer->payment_method == "paypal") {
             WC()->session->paymentId = $payment->id;
             //set payment id for later use, we need this to execute payment
             return $payment->links[1]->href;
         }
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         wc_add_notice(__("Error processing checkout. Please try again. ", 'woocommerce'), 'error');
         $this->add_log($ex->getData());
     } catch (Exception $ex) {
         wc_add_notice(__('Error processing checkout. Please try again. ', 'woocommerce'), 'error');
         $this->add_log($ex->getMessage());
     }
 }
Пример #22
0
 public function postPayment()
 {
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $_contentCart = Cart::instance('shopping')->content();
     $_itemsCount = Cart::instance('shopping')->count();
     $_arryItems = array();
     $_i = 0;
     foreach ($_contentCart as $row) {
         if ($_i < $_itemsCount) {
             $item = new Item();
             $item->setName($row->name)->setDescription($row->name)->setCurrency('AUD')->setQuantity((double) $row->qty)->setTax((double) ($row->price * 10) / 100)->setPrice((double) $row->price);
             //$435.00
             $_arryItems[$_i] = $item;
             $_i++;
         }
     }
     $item_list = new ItemList();
     $item_list->setItems(array($_arryItems));
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems($_arryItems);
     //==================== LIST ITEMS IN SHOPPING CART ========= //
     $details = new Details();
     $details->setShipping("0")->setTax((string) (Cart::instance('shopping')->total() * 10) / 100)->setSubtotal((string) Cart::instance('shopping')->total());
     $amount = new Amount();
     $amount->setCurrency("AUD")->setTotal((string) Cart::instance('shopping')->total() + Cart::instance('shopping')->total() * 10 / 100)->setDetails($details);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription('QLM Shopping Cart');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::to('/payment/status'))->setCancelUrl(URL::to('/payments/cancel'));
     $payment = new Payment();
     $payment->setIntent('Sale')->setPayer($payer)->setRedirectUrls($redirect_urls)->setTransactions(array($transaction));
     try {
         //$this->createInvoice();
         $payment->create($this->_api_context);
     } catch (\PayPal\Exception\PayPalConnectionException $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 View::make('pages.shoppingcart')->with('error', 'Unknown error occurred');
 }
Пример #23
0
 public function CreatePayment($items = false, $data = false)
 {
     $apiContext = $this->getApiContext();
     $data = (object) $data;
     #die(print_r($data));
     // ### Payer
     // A resource representing a Payer that funds a payment
     // For paypal account payments, set payment method
     // to 'paypal'.
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // ### Itemized information
     // (Optional) Lets you specify item wise
     // information
     $cart = array();
     $total = 0;
     /*foreach($items as $item)
         {
           $itemC = new Item();
           $itemC->setName($item->name)
               ->setCurrency('EUR')
               ->setQuantity($item->items)
               ->setSku($item->code ? $item->code : $item->id)
               ->setPrice(round($item->cost,2));
           $cart[] = $itemC;
           $total += $item->items * $item->cost;
         }
     
         $itemList = new ItemList();
         $itemList->setItems($cart);*/
     // ### Additional payment details
     // Use this optional field to set additional
     // payment information such as tax, shipping
     // charges etc.
     $details = new Details();
     $details->setShipping(round($data->shipping, 2))->setTax(round($data->tax, 2))->setSubtotal(round($data->subtotal, 2));
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     $amount = new Amount();
     $amount->setCurrency("EUR")->setTotal(round($data->total, 2))->setDetails($details);
     // ### 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)->setDescription("Compra actual - " . round($data->total, 2) . " EUR")->setInvoiceNumber(uniqid());
     // ### Redirect urls
     // Set the urls that the buyer must be redirected to after
     // payment approval/ cancellation.
     $baseUrl = base_url();
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl("{$baseUrl}cart/paypal?success=true")->setCancelUrl("{$baseUrl}cart/paypal-ko");
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent set to 'sale'
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     // ### Create Payment
     // Create a payment by calling the 'create' method
     // passing it a valid apiContext.
     // (See bootstrap.php for more on `ApiContext`)
     // The return object contains the state and the
     // url to which the buyer must be redirected to
     // for payment approval
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
         die(print_r($ex->getData()));
         exit(1);
     }
     // ### Get redirect url
     // The API response provides the url that you must redirect
     // the buyer to. Retrieve the url from the $payment->getApprovalLink()
     // method
     $approvalUrl = $payment->getApprovalLink();
     // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
     redirect($approvalUrl);
     return $payment;
 }
 /**
  * Creates PayPal payment details from given order
  *
  * @param OrderInterface $order
  *
  * @return Details
  */
 protected function createDetails(OrderInterface $order) : Details
 {
     $details = new Details();
     $details->setShipping($order->getShippingTotal()->getNetAmount());
     $details->setTax($order->getOrderTotal()->getTaxAmount());
     $details->setSubtotal($order->getProductTotal()->getNetAmount());
     return $details;
 }
Пример #25
0
// A resource representing a Payer's funding instrument.
// For direct credit card payments, set the CreditCard
// field on this object.
$fi = new FundingInstrument();
$fi->setCreditCard($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));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
// charges etc.
$details = new Details();
$details->setShipping($shipping)->setTax($tax)->setSubtotal($amount);
// ### Amount
// Lets you specify a payment amount.
// You can also specify additional details
// such as shipping, tax.
$amount = new Amount();
$amount->setCurrency("USD")->setTotal($total)->setDetails($details);
// ### 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)->setInvoiceNumber(uniqid());
// ### Payment
// A Payment Resource; create one using
Пример #26
0
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item1 = new Item();
$item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setSku("123123")->setPrice(100);
$item2 = new Item();
$item2->setName('Granola bars')->setCurrency('USD')->setQuantity(1)->setSku("321321")->setPrice(100);
$itemList = new ItemList();
$itemList->setItems(array($item1, $item2));
$details = new Details();
$details->setShipping(1.2)->setTax(1.3)->setSubtotal(200);
$fakeTotal = 200 + 1.2 + 1.3;
$amount = new Amount();
$amount->setCurrency("USD")->setTotal($fakeTotal)->setDetails($details);
$transaction = new Transaction();
$transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl('http://localhost:9090/member/executePayment.php?success=true')->setCancelUrl('http://localhost:9090/member/executePayment.php?success=false');
$payment = new Payment();
$payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
$request = clone $payment;
try {
    $payment->create($api);
    echo 'payment';
} catch (Exception $ex) {
Пример #27
0
<?php

use PayPal\Api\Payer;
use PayPal\Api\Details;
use PayPal\Api\Amount;
use PayPal\Api\Transaction;
use PayPal\Api\Payment;
use PayPal\Api\RedirectUrls;
use PayPal\Exception\PPConnectionException;
require '../src/start.php';
$payer = new Payer();
$details = new Details();
$amount = new Amount();
$transaction = new Transaction();
$payment = new Payment();
$redirectUrls = new RedirectUrls();
$payer->setPaymentMethod('paypal');
$details->setShipping('2.00')->setTax('0.00')->setSubtotal('20.00');
$amount->setCurrency('GBP')->setTotal('22.00')->setDetails($details);
$transaction->setAmount($amount)->setDescription('Membership');
$payment->setIntent('sale')->setPayer($payer)->setTransactions([$transaction]);
$redirectUrls->setReturnUrl('http://localhost/paypal/paypal/pay.php?approved=true')->setCancelUrl('http://localhost/paypal/paypal/pay.php?approved=false');
$payment->setRedirectUrls($redirectUrls);
try {
    $payment->create($api);
    $hash = md5($payment->getId());
    // var_dump($hash); die();
    $_SESSION['paypal_hash'] = $hash;
    $store = $db->prepare("INSERT INTO transaction_paypal VALUES('',?,?,?,?)");
    $store->bindValue(1, $_SESSION['user_id'], PDO::PARAM_INT);
    $store->bindValue(2, $payment->getId(), PDO::PARAM_INT);
 public function postPayment()
 {
     $paypal_conf = Config::get('paypal');
     $apiContext = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
     $apiContext->setConfig($paypal_conf['settings']);
     $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));
     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);
     var_dump($payment);
     echo "string";
     /*exit;
             $payer = new Payer();
             $payer->setPaymentMethod('paypal');
     
             $item_1 = new Item();
             $item_1->setName('Item 1') // item name
                 ->setCurrency('USD')
                 ->setQuantity(2)
                 ->setPrice('15'); // unit price
     
             $item_2 = new Item();
             $item_2->setName('Item 2')
                 ->setCurrency('USD')
                 ->setQuantity(4)
                 ->setPrice('7');
     
             $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(78);
     
             $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());
     
             if(isset($redirect_url)) {
                 // redirect to paypal
                 return Redirect::away($redirect_url);
             }
     
             return Redirect::route('original.route')
                 ->with('error', 'Unknown error occurred');*/
 }
Пример #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;
 }
Пример #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;
 }