Esempio n. 1
0
 /**
  * @Route("/{id}/pay")
  * @Method({"GET"})
  */
 public function initiatePayment($id)
 {
     $order = $this->getOrderManager()->findById($id);
     if (!$order) {
         return $this->fail();
     }
     if ($order->getDeposited() && $order->getPaid()) {
         return $this->fail();
     }
     $price = !$order->getDeposited() ? 1 : 100 - 25;
     $clientId = $this->container->getParameter('paypal_client_id');
     $secret = $this->container->getParameter('paypal_secret');
     $sdkConfig = $this->container->getParameter('paypal_sdk_config');
     $cred = new \PayPal\Auth\OAuthTokenCredential($clientId, $secret);
     $accessToken = $cred->getAccessToken($sdkConfig);
     $apiContext = new \PayPal\Rest\ApiContext($cred);
     $apiContext->setConfig($sdkConfig);
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod('paypal');
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency('USD');
     $amount->setTotal($price);
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setDescription('7L High School Mum Shoppe');
     $transaction->setAmount($amount);
     $redirectUrls = new \PayPal\Api\RedirectUrls();
     $redirectUrls->setReturnUrl('http://127.0.0.1/mumshoppe/web/app_dev.php/shop#/pay/' . $order->getId());
     $redirectUrls->setCancelUrl('http://127.0.0.1/mumshoppe/web/app_dev.php/shop');
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $response = $payment->create($apiContext);
     foreach ($response->getLinks() as $link) {
         if ($link->getRel() === 'approval_url') {
             return $this->respondJson(array('success' => true, 'access_token' => $cred, 'location' => $link->getHref(), 'payment_id' => $response->getId()));
         }
     }
     return $this->fail();
 }
function create_paypal_payment($total, $currency, $desc, $my_items, $redirect_url, $cancel_url)
{
    $redirectUrls = new PayPal\Api\RedirectUrls();
    $redirectUrls->setReturnUrl($redirect_url);
    $redirectUrls->setCancelUrl($cancel_url);
    $payer = new PayPal\Api\Payer();
    $payer->setPaymentMethod("paypal");
    $amount = new PayPal\Api\Amount();
    $amount->setCurrency($currency);
    $amount->setTotal($total);
    $items = new PayPal\Api\ItemList();
    $items->setItems($my_items);
    $transaction = new PayPal\Api\Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription($desc);
    $transaction->setItemList($items);
    $payment = new PayPal\Api\Payment();
    $payment->setRedirectUrls($redirectUrls);
    $payment->setIntent("sale");
    $payment->setPayer($payer);
    $payment->setTransactions(array($transaction));
    $payment->create(apiContext());
    return $payment;
}
Esempio n. 3
0
 public function actionStep2()
 {
     // require_once(Yii::getPathOfAlias('application.components.Paypal') . '/autoload.php');
     $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/classic/views/layouts";
     $this->layout = 'nonPrepare';
     $this->checkSession(2);
     $request = Yii::app()->request;
     if ($request->isPostRequest && isset($_POST)) {
         try {
             $this->card_number = $this->getPostFilter('card_number');
             $this->card_holder_name = $this->getPostFilter('card_holder_name');
             $this->expiry_year = $this->getPostFilter('expiry_year');
             $this->expiry_month = $this->getPostFilter('expiry_month');
             $this->cvc = $this->getPostFilter('cvc');
             $this->first_name = $this->getPostFilter('first_name');
             $this->last_name = $this->getPostFilter('last_name');
             $this->bill_city = $this->getPostFilter('bill_city');
             $this->bill_address = $this->getPostFilter('bill_address');
             $this->bill_country = $this->getPostFilter('bill_country');
             $this->bill_postcode = $this->getPostFilter('bill_postcode');
             $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential("AZxYt_EVUMu9xXO0DHBHn4KGUVx6UMIdQKAb7QeCek609Zo3lFCAIfIKs29-T4PL66cSoN6189SfoACj", "ELebkFS3jmn9CNu4PF1t8OWaIsHASMDalHKp9x1dwEo0KmeKo582SfeVIC3CC99tmin7NoJZp00jI2Oc"));
             $addr = new \PayPal\Api\Address();
             $addr->setLine1($this->bill_address);
             $addr->setCity($this->bill_city);
             $addr->setCountryCode($this->bill_country);
             $addr->setPostalCode($this->bill_postcode);
             $addr->setState('OH');
             $card = new \PayPal\Api\CreditCard();
             $card->setNumber($this->card_number);
             $card->setType('visa');
             $card->setExpireMonth($this->expiry_month);
             $card->setExpireYear($this->expiry_year);
             $card->setCvv2($this->cvc);
             $card->setFirstName($this->first_name);
             $card->setLastName($this->last_name);
             $card->setBillingAddress($addr);
             $fi = new \PayPal\Api\FundingInstrument();
             $fi->setCreditCard($card);
             $payer = new \PayPal\Api\Payer();
             $payer->setPaymentMethod('credit_card');
             $payer->setFundingInstruments(array($fi));
             $amount = new \PayPal\Api\Amount();
             $amount->setCurrency('USD');
             $amount->setTotal('0.12');
             $transaction = new \PayPal\Api\Transaction();
             $transaction->setAmount($amount);
             $transaction->setDescription('This is the payment transaction description.');
             $redirectUrls = new \PayPal\Api\RedirectUrls();
             $redirectUrls->setReturnUrl(Yii::app()->createAbsoluteUrl('bookService/step3' . '?success=true'))->setCancelUrl(Yii::app()->createAbsoluteUrl('bookService/step3' . '?success=false'));
             $payment = new \PayPal\Api\Payment();
             $payment->setIntent('sale');
             $payment->setPayer($payer);
             $payment->setTransactions(array($transaction));
             try {
                 $res = $payment->create($apiContext);
             } catch (PayPal\Exception\PayPalConnectionException $e) {
                 echo $e->getData();
                 // This will print a JSON which has specific details about the error.
                 // exit(1);
             }
             $this->nextStep(3);
             if (ERunActions::runBackground()) {
                 $this->SendMailConfirm();
             }
             // die();
             $this->redirectStep(3);
         } catch (exception $e) {
             var_dump($e->getMessage());
         }
     }
     $this->render('step2');
 }
 private static function _getCancelUrl(PayPal\Api\RedirectUrls &$redirectUrls)
 {
     return $redirectUrls->getCancelUrl();
 }
Esempio n. 5
0
 protected function initializePay($package, $user)
 {
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod('paypal');
     $total = $package->price + $package->tax;
     $item = new \PayPal\Api\Item();
     $item->setName($package->name)->setCurrency('USD')->setQuantity(1)->setPrice($package->price);
     $itemList = new \PayPal\Api\ItemList();
     $itemList->setItems([$item]);
     $details = new \PayPal\Api\Details();
     $details->setTax($package->tax)->setSubtotal($package->price);
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency("USD")->setTotal($total)->setDetails($details);
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($package->name)->setInvoiceNumber(uniqid());
     $baseUrl = "http://trafficmonitor.ca/";
     $redirectUrls = new \PayPal\Api\RedirectUrls();
     $redirectUrls->setReturnUrl($baseUrl . "plan/success")->setCancelUrl($baseUrl . "packages");
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($this->paypal());
         $transaction = new Transaction(array("user_id" => $user->id, "property" => "package", "property_id" => $package->id, "payment_id" => $payment->getId(), "amount" => $total));
         $transaction->save();
     } catch (Exception $e) {
         die($e);
     }
     return $approvalUrl = $payment->getApprovalLink();
 }
Esempio n. 6
0
 public function direct()
 {
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod('paypal');
     $items = array();
     foreach ($this->items as $item) {
         $item2 = new \PayPal\Api\Item();
         $item2->setName($item[0])->setDescription($item[1])->setCurrency(CURRENCY)->setQuantity($item[2])->setPrice($item[3]);
         $items[] = $item2;
     }
     $itemList = new \PayPal\Api\ItemList();
     $itemList->setItems($items);
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency(CURRENCY)->setTotal($this->total);
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setDescription($this->description)->setItemList($itemList)->setAmount($amount);
     $redirectUrls = new \PayPal\Api\RedirectUrls();
     $redirectUrls->setReturnUrl($this->success_url)->setCancelUrl($this->cancel_url);
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent($this->intent)->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($this->apiContext);
         return array('id' => $payment->getId(), 'total' => $this->total, 'items' => $this->items, 'details' => $this->description, 'state' => $payment->getstate(), 'href' => $payment->getApprovalLink());
     } catch (Exception $e) {
         throw new \Exception('PayPal error: ' . $e->getMessage());
     }
 }
Esempio n. 7
0
     } else {
         //sandbox stuff
         $cred = new \PayPal\Auth\OAuthTokenCredential("ATNYSszAJLwQn-K4tIPlrVFsR5bKiAN6I07AQkR5pRh-tNllccoGn7bzRtcTZpjM6BgeAfKBAoSpS2sC", "EJQp7OmMT9pjTehZFOvHq5y2aBe5WQlelGH3MZSnd6XFPWdAB9ctwya3OKX9kWFaYTQTR8Vo0m47VPc6", $sdkConfig);
     }
     $apiContext = new \PayPal\Rest\ApiContext($cred, 'Request' . time());
     $apiContext->setConfig($sdkConfig);
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod("paypal");
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency("EUR");
     $amount->setTotal("{$price}");
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setDescription("Deine Bestellung bei Alma Mater Wear");
     $transaction->setAmount($amount);
     //$baseUrl = getBaseUrl();
     $redirectUrls = new \PayPal\Api\RedirectUrls();
     $redirectUrls->setReturnUrl($success_url);
     $redirectUrls->setCancelUrl($error_url);
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $payment->create($apiContext);
     //Nach erfolgreicher Bezahlung wird der Bezahlstatus auf 1 gesetzt. Dafür wird die Payment ID in der Datenbank gespeichert
     mysqli_query($link, "UPDATE orders SET paymentID = '{$payment->id}' WHERE id = {$orderId}");
     //Der Ziellink wird ausgegeben und per JavaScript geöffnet
     $referer = $payment->links[1]->href;
     echo $referer;
 } else {
     if (USE_LIVE_PAYMENT) {