/** * Make a EWAY payment to the destined user from the main business account. * * @return void */ protected function makePayment() { $receiver = Input::get('number'); $amounttosend = Input::get('amount'); $currency = Input::get('currency'); $destinationProvider = Input::get('target'); $charges = new PlatformCharges($amounttosend, $currency, $destinationProvider); $desc = $charges->getReceiverType($destinationProvider); $user = User::find(Auth::user()->id); $transaction = ['Customer' => ['FirstName' => Auth::user()->name, 'Street1' => 'Level 5', 'Country' => 'US', 'Mobile' => Auth::user()->number, 'Email' => Auth::user()->email], 'Items' => [['SKU' => mt_rand(), 'Description' => 'Hybrid Transfer from EWAY to ' . $desc . ' user', 'Quantity' => 1, 'UnitCost' => $charges->convertCurrency($currency, 'AUD', $charges->getDueAmount('ew', $destinationProvider)), 'Tax' => 100]], 'Options' => [['Value' => $desc], ['Value' => $receiver], ['Value' => 'AUD'], ['Value' => 0.01 * $amounttosend]], 'Payment' => ['TotalAmount' => $charges->convertCurrency($currency, 'AUD', $charges->getDueAmount('ew', $destinationProvider)) * 100, 'CurrencyCode' => 'AUD'], 'Method' => 'ProcessPayment', 'RedirectUrl' => URL::route('dashboard') . '/ewayconfirm', 'CancelUrl' => URL::route('dashboard') . '/ewaycancel', 'PartnerID' => EwayController::$_EWAY_CUSTOMER_ID, 'TransactionType' => \Eway\Rapid\Enum\TransactionType::PURCHASE, 'Capture' => true, 'LogoUrl' => 'https://izepay.iceteck.com/public/images/logo.png', 'HeaderText' => 'Izepay Money Transfer', 'Language' => 'EN', 'CustomView' => 'BootstrapCerulean', 'VerifyCustomerEmail' => true, 'Capture' => true, 'CustomerReadOnly' => false]; try { $response = $this->client->createTransaction(\Eway\Rapid\Enum\ApiMethod::RESPONSIVE_SHARED, $transaction); //var_dump($response); // echo $response->SharedPaymentUrl; //sleep(20); } catch (Exception $ex) { return Redirect::route('dashboard')->with('alertError', 'Debug Error: ' . $ex->getMessage()); } //manage response if (!$response->getErrors()) { // Redirect to the Responsive Shared Page header('Location: ' . $response->SharedPaymentUrl); //die(); } else { foreach ($response->getErrors() as $error) { //echo "Response Error: ".\Eway\Rapid::getMessage($error)."<br>"; return Redirect::route('dashboard')->with('alertError', 'Error! ' . \Eway\Rapid::getMessage($error)); } } }
public function postPayment() { $name = 'Transaction'; $mmnumber = Input::get('number'); $amounttosend = Input::get('amount'); $currency = Input::get('currency'); $type = Input::get('target'); //destination/receipient's payment Provider $cno = Input::get('cardnumber'); $charges = new PlatformCharges($amounttosend, $currency, $type); $desc = $charges->getReceiverType($type); Session::set('destProvider', $type); Session::set('destination', $mmnumber); if ($type == 'pp') { return Redirect::route('dashboard')->with('alertError', 'You need to select different payment provider for sender and receiver'); } $payer = new Payer(); $payer->setPaymentMethod('paypal'); // Valid Values: ["credit_card", "bank", "paypal", "pay_upon_invoice", "carrier"] //TODO:: try to deduce the receiver type (email or number) and set the payerinfo data correctly for consistency $payerInfo = new PayerInfo(); $payerInfo->setFirstName($mmnumber); //used to represent the receiver name/number/email $payerInfo->setLastName('Paypal to ' . $desc); //used to pass the transaction type in the request $payer->setPayerInfo($payerInfo); $item_1 = new Item(); $item_1->setName('Money Transfer')->setDescription("Send money to a {$desc} User")->setCurrency('USD')->setQuantity(1)->setPrice($charges->getDueAmount('pp', $type)); // unit price) // add item to list $item_list = new ItemList(); $item_list->setItems(array($item_1)); $amount = new Amount(); $amount->setCurrency('USD')->setTotal($charges->getDueAmount('pp', $type)); $transaction = new Transaction(); $transaction->setAmount($amount)->setItemList($item_list)->setDescription('Send money To a Mobile Money User'); $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); 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 "Error!!!!"; } catch (\PayPal\Exception\PPConnectionException $ex) { if (\Config::get('app.debug')) { echo "Exception: " . $ex->getMessage() . PHP_EOL; $err_data = json_decode($ex->getData(), true); return Redirect::route('dashboard')->with('alertError', 'Connection error. $err_data'); exit; } else { return Redirect::route('dashboard')->with('alertError', 'Connection error occured. Please try again later. ' . $ex->getMessage()); // die('Some error occurred, sorry for the inconvenience. Our team has been notified to correct this error.'); } } catch (Exception $ex) { return Redirect::route('dashboard')->with('alertError', 'Error! ' . $ex->getMessage()); } }