$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
/** * @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(); }