/** * Purchase Paypal Response * @param Request $request * @return $this */ public function purchasePaypalResponse(Request $request) { $config = array('mode' => $this->modeApiPaypal, 'acct1.UserName' => $this->userApiPaypal, 'acct1.Password' => $this->passwordApiPaypal, 'acct1.Signature' => $this->signatureApiPaypal); //getExpressCheckout $getExpressCheckoutDetailsRequest = new GetExpressCheckoutDetailsRequestType($request->token); $getExpressCheckoutReq = new GetExpressCheckoutDetailsReq(); $getExpressCheckoutReq->GetExpressCheckoutDetailsRequest = $getExpressCheckoutDetailsRequest; $paypalService = new PayPalAPIInterfaceServiceService($config); $getECResponse = $paypalService->GetExpressCheckoutDetails($getExpressCheckoutReq); //DoExpressCheckout $DoECRequestDetails = new DoExpressCheckoutPaymentRequestDetailsType(); $DoECRequestDetails->PayerID = $request->PayerID; $DoECRequestDetails->Token = $request->token; $DoECRequestDetails->PaymentDetails[0] = $getECResponse->GetExpressCheckoutDetailsResponseDetails->PaymentDetails[0]; //$DoECRequestDetails->PaymentAction = "Sale"; $DoECRequest = new DoExpressCheckoutPaymentRequestType(); $DoECRequest->DoExpressCheckoutPaymentRequestDetails = $DoECRequestDetails; $DoECReq = new DoExpressCheckoutPaymentReq(); $DoECReq->DoExpressCheckoutPaymentRequest = $DoECRequest; $DoECResponse = $paypalService->DoExpressCheckoutPayment($DoECReq); $purchaseOperationNumber = ""; //dd($DoECResponse); list($product, $items, $total) = $this->getPurchasedOptions($getECResponse->GetExpressCheckoutDetailsResponseDetails->Custom); if ($DoECResponse->Ack == 'Success') { $purchaseOperationNumber = $DoECResponse->DoExpressCheckoutPaymentResponseDetails->PaymentInfo[0]->TransactionID; //guardamos la operacion en db si no existe ya el mismo numero de operación $exitsPayment = $this->paymentRepository->findByOperationNumber($purchaseOperationNumber); if (!$exitsPayment) { $payment = $this->paymentRepository->store(['product_id' => $product->id, 'purchaseOperationNumber' => $purchaseOperationNumber]); } //actualizamos el estado del producto recien ingresado a publicado $this->productRepository->update_state($product->id, 1); // 0:inactivo 1:publicado 2:en espera 3:inactivo(pago rechazado o denegado) // informamos via email del producto recien creado y su confirmacion de pago try { $this->mailer->paymentConfirmation(['email' => Auth()->user()->email, 'product' => $product, 'items' => $items, 'total' => $total]); } catch (Swift_RfcComplianceException $e) { Log::error($e->getMessage()); } } else { //actualizamos el estado del producto recien ingresado inactivo si el pago fue denegado $this->productRepository->update_state($product->id, 3); // 0:inactivo 1:publicado 2:en espera 3:inactivo(pago rechazado o denegado) } $authorizationResult = $DoECResponse->Ack; Log::info('results of PAYPAL: ' . json_encode($DoECResponse)); return view('products.purchase-response')->with(compact('items', 'total', 'authorizationResult', 'purchaseOperationNumber')); }