function execute_payment($payment_id, $payer_id)
{
    $payment = PayPal\Api\Payment::get($payment_id, apiContext());
    $payment_execution = new PayPal\Api\PaymentExecution();
    $payment_execution->setPayerId($payer_id);
    $payment = $payment->execute($payment_execution, apiContext());
    return $payment;
}
Exemple #2
0
            $anhang["type"] = mime_content_type($pfad);
        } else {
            $anhang["type"] = "application/octet-stream";
        }
        $anrede = $row->anrede == "Frau" ? "geehrte Frau" : "geehrter Herr";
        mail_att($row->email, "Alma Mater Wear: Ihre Rechnung", html_mail($paymentId), $anhang);
        //PayPal SDK konfogurieren
        $sdkConfig = array("mode" => "sandbox");
        if (USE_LIVE_PAYMENT) {
            $sdkConfig["mode"] = "live";
        }
        //Bezahlvorgang abschließen
        if (USE_LIVE_PAYMENT) {
            // actual client ID and secret
            $cred = new \PayPal\Auth\OAuthTokenCredential("Ac_RSNJ2Ss-8Ba7X3TIrveIa-g5p_E_7J_7BukY-_q2MwutfbVvLQAhBHF89Ri2LzHeRtOSZRNPSSG7l", "EK91XgzYqNA-bqlzWQndkXaKw8_tl1ENjSVrW3htCQFZV7sGk6_5mcJGqCcYQizVPUSvMVwIHIh4lymQ", $sdkConfig);
        } else {
            //sandbox stuff
            $cred = new \PayPal\Auth\OAuthTokenCredential("ATNYSszAJLwQn-K4tIPlrVFsR5bKiAN6I07AQkR5pRh-tNllccoGn7bzRtcTZpjM6BgeAfKBAoSpS2sC", "EJQp7OmMT9pjTehZFOvHq5y2aBe5WQlelGH3MZSnd6XFPWdAB9ctwya3OKX9kWFaYTQTR8Vo0m47VPc6", $sdkConfig);
        }
        $apiContext = new \PayPal\Rest\ApiContext($cred, 'Request' . time());
        $apiContext->setConfig($sdkConfig);
        $payment = new \PayPal\Api\Payment();
        $payment->setId($paymentId);
        $execution = new \PayPal\Api\PaymentExecution();
        $execution->setPayerId("{$payerId}");
        $response = $payment->execute($execution, $apiContext);
        // var_dump($response);
        // header("Location: shop.html?checkout=success");
    }
}
//SOFORT wird separat abgewickelt
Exemple #3
0
 public function success()
 {
     $paymentId = RequestMethods::get("paymentId");
     $payerId = RequestMethods::get("PayerID");
     if (isset($paymentId)) {
         $payment = \PayPal\Api\Payment::get($paymentId, $this->paypal());
         $execute = new \PayPal\Api\PaymentExecution();
         $execute->setPayerId($payerId);
         try {
             $result = $payment->execute($execute, $this->paypal());
             if ($result) {
                 $transaction = Transaction::first(array("payment_id = ?" => $paymentId));
                 if ($transaction) {
                     $transaction->live = 1;
                     $transaction->save();
                     $this->addSubscription($transaction);
                 }
             }
         } catch (Exception $e) {
             die('Error, Please contact to info@trafficmonitor.ca');
         }
     } else {
         die('Error, Please contact to info@trafficmonitor.ca');
     }
 }
Exemple #4
0
 /**
  * @Route("/{id}/pay/")
  * @Method({"POST"})
  */
 public function finalizePayment(Request $request, $id)
 {
     try {
         $cred = $request->request->get('access_token');
         $payment_id = $request->request->get('payment_id');
         $payer_id = $request->request->get('payer_id');
         if (!$cred || !$payment_id || !$payer_id) {
             throw new Error();
         }
     } catch (Exception $ex) {
         return $this->fail();
     }
     $order = $this->getOrderManager()->findById($id);
     if (!$order) {
         return $this->fail();
     }
     if ($order->getDeposited() && $order->getPaid()) {
         return $this->fail();
     }
     $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);
     $apiContext = new \PayPal\Rest\ApiContext($cred);
     $apiContext->setConfig($sdkConfig);
     $payment = new \PayPal\Api\Payment();
     $payment->setId($payment_id);
     $execution = new \PayPal\Api\PaymentExecution();
     $execution->setPayerId($payer_id);
     try {
         $payment->execute($execution, $apiContext);
     } catch (Exception $ex) {
         return $this->fail();
     }
     $transaction = new Transaction($payment_id, new \DateTime('now'));
     if (!$order->getDeposited()) {
         $order->setDeposited(true);
         $order->setDeposit($transaction);
     } else {
         $order->setPaid(true);
         $order->setPayment($transaction);
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($transaction);
     $em->persist($order);
     $em->flush();
     return $this->succeed();
 }
Exemple #5
0
 public function execute_payment()
 {
     $payment = \PayPal\Api\Payment::get($_GET['paymentId'], $this->apiContext);
     $execution = new \PayPal\Api\PaymentExecution();
     $execution->setPayerId($_GET['PayerID']);
     try {
         $payment->execute($execution, $this->apiContext);
         return array('id' => $payment->getId(), 'state' => $payment->getstate());
     } catch (Exception $e) {
         throw new \Exception('PayPal error: ' . $e->getMessage());
     }
 }