Esempio n. 1
0
 public function postPayment()
 {
     $name = 'Transaction';
     /*$mmnumber      = Input::get('number');
       $amounttosend     = Input::get('amount');
       $currency   = Input::get('currency');*/
     $mmnumber = Input::get('number');
     $amounttosend = Input::get('amount');
     $currency = Input::get('currency');
     $charges = new PlatformCharges($amounttosend, $currency);
     $payer = new Payer();
     $payer->setPaymentMethod('paypal');
     $item_1 = new Item();
     $item_1->setName('Transaction')->setCurrency('USD')->setQuantity(1)->setPrice((int) $charges->getDueAmountForPayPalToMobileMoney());
     // unit price
     // add item to list
     $item_list = new ItemList();
     $item_list->setItems(array($item_1));
     $amount = new Amount();
     $amount->setCurrency('USD')->setTotal((int) $charges->getDueAmountForPayPalToMobileMoney());
     $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);
     } catch (\PayPal\Exception\PPConnectionException $ex) {
         if (\Config::get('app.debug')) {
             echo "Exception: " . $ex->getMessage() . PHP_EOL;
             $err_data = json_decode($ex->getData(), true);
             exit;
         } else {
             die('Some error occurred, sorry for inconvenient');
         }
     }
     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!!!!";
     /*Redirect::route('original.route')
       ->with('error', 'Unknown error occurred'); */
 }
Esempio n. 2
0
 public function convert()
 {
     $from = Input::get('from');
     $to = Input::get('to');
     $amount = (double) Input::get('amount');
     $converter = new PlatformCharges($amount, $from, $to);
     //        echo round($converter->convertCurrency($from, $to, $amount), 2) .' '.$to ;
     echo round($converter->convertCurrency($from, $to, $amount), 3) . ' ' . $to;
 }
Esempio n. 3
0
 /**
  * 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));
         }
     }
 }
Esempio n. 4
0
 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());
     }
 }
Esempio n. 5
0
 /**
  * Make a MM payment to the destined user from the main business account.
  * @return void
  */
 public function requestPayment()
 {
     //parameters fetched from ajax request
     $AccountID = 4420274;
     $Phonenumber = Input::get('to');
     //number of the person who initiated the request
     $Amount = Input::get('amount');
     //amount to charge the sender
     $destination = Input::get('receivercontact');
     //other address of the receiver
     $dest_provider = Input::get('provider');
     //provider platform to send the funds in
     $currency = Input::get('currency');
     //currency to use
     $sendto = Input::get('receiver');
     //funds are sent to this user
     $initAmount = $Amount;
     $Amount = (int) $Amount + 2 / 100 * $Amount;
     $mes_donnees = array('MyAccountID' => $AccountID, 'CustomerPhonenumber' => $Phonenumber, 'Amount' => $Amount);
     $postdata = http_build_query($mes_donnees);
     $url = 'http://api.furthermarket.com/FM/MTN/MoMo/requestpayment?';
     //make request and fetch result
     $ch = curl_init();
     //  Initiate curl
     curl_setopt($ch, CURLOPT_TIMEOUT, 300);
     //timeout in seconds (300)
     //	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
     //	curl_setopt($ch, CURLOPT_POST, 1);
     //	curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
     //	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','Content-Length:'.strlen($url.$postdata)));
     curl_setopt($ch, CURLOPT_HEADER, 0);
     //TRUE to include the header in the output.
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
     //0 = wait indefinitely while trying to connect
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     // Will return the response, if false it print the response
     curl_setopt($ch, CURLOPT_URL, $url . $postdata);
     // Set the url
     $result = curl_exec($ch);
     // Execute
     $httpstatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
     $curl_errno = curl_errno($ch);
     /*
     $opts = array('http' =>
                 array(
                            'method'  => 'GET',
                            'header'  => 'Content-type: text/xml',
                            'CharSet' => 'utf-8',
                            'content' => $postdata
                     )
     );
     
     $context = stream_context_create($opts);
     $UssdResult = file_get_contents('http://api.furthermarket.com/FM/MTN/MoMo/requestpayment?MyaccountID='.$AccountID
                                     .'&CustomerPhonenumber='.$Phonenumber
                                     .'&Amount='.$Amount
                                     .'&ItemDesignation=MoMoPayment&ItemDescription=SendMomoto_'.$dest_provider.'_user',
                                      1, $context);
     
     header('Content-Type:text/javascript');
     */
     //process the result here
     $params = explode(',', $result, 3);
     //[0] = 1 or 0, [1] = payment id, [2] = message for success
     //create amount to send to user provider in USD
     $montant = new PlatformCharges($initAmount, 'XAF', $dest_provider);
     if ($params[0] == 1 && isset($params[2])) {
         //verify for successful transaction and save to db and email receipt
         $transaction = new IcePayTransaction();
         $transaction->user_id = Auth::user()->id;
         $transaction->tid = $params[1];
         //transaction id or transaction bordereaux
         $transaction->sender_email = Auth::user()->email;
         //sender's email
         $transaction->receiver_email = $sendto;
         //receiver's email or number)
         $transaction->type = 'MOMO_TO_' . $dest_provider;
         $transaction->status = 'pending';
         $transaction->amount = $Amount;
         //total amount deducted and transferred. The amount to be transfered to the receiver is initial $amount without our charges(2%) applied.
         $transaction->currency = $currency;
         $transaction->save();
         $email = Auth::user()->email;
         //
         $username = Auth::user()->username;
         //send transaction email to sender confirming transactions in a professional way. send copy to company(Paygray)
         Mail::send(['html' => 'emails.auth.transactions'], array('tdate' => date('Y-m-d H:i:s'), 'tid' => $result->getId(), 'sender_email' => Auth::user()->email, 'sender_number' => Auth::user()->number, 'receiver_email' => $sendto, 'receiver_number' => $destination, 'status' => 'PENDING', 'amount' => $initAmount, 'charge' => '2% of ' . $initAmount . ' in ' . $currency, 'total' => $montant->getDueAmount('mm', $dest_provider), 'mode' => $result->getPayer()->getPayerInfo()->getLastName()), function ($message) use($email, $username) {
             $message->to(array($email, '*****@*****.**', '*****@*****.**'), $username)->subject('Transaction Receipt - Incoming');
         });
         echo json_encode(array('paymentresult' => $result, 'message' => 'Transaction successful', 'error_no' => $curl_errno));
     } else {
         echo json_encode(array('paymentresult' => $result, 'message' => 'Transaction failed', 'error_no' => $curl_errno));
     }
 }
Esempio n. 6
0
 public function payWithPaypal()
 {
     //purchase parameters
     $mmnumber = Input::get('number');
     $apikey = Input::get('apikey');
     $amounttosend = Input::get('amount');
     $currency = Input::get('currency');
     $item = Input::get('item_name');
     $cancel_url = Input::get('cancel_url');
     $confirm_url = Input::get('confirm_url');
     // $cno        = Input::get('cardnumber');
     $developers = Developer::where('dev_key', '=', $apikey)->where('dev_status', '=', 1)->limit(1)->get();
     if ($developers != null) {
         foreach ($developers as $developer) {
             $mmnumber = $developer->dev_email . ' | ' . $developer->dev_number . ' | ' . $developer->dev_username;
             $type = $developer->dev_paymentprovider;
             //   echo $mmnumber;
             //  echo '<BR/>'.$type;
         }
     } else {
         Redirect::away($cancel_url);
     }
     $charges = new PlatformCharges($amounttosend, $currency, $type);
     //        $desc    = $charges->getReceiverType($type);
     Session::set('destProvider', $type);
     Session::set('destination', $mmnumber);
     $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('Item: ');
     //used to pass the transaction type in the request
     $payer->setPayerInfo($payerInfo);
     $item_1 = new Item();
     $item_1->setName('Item purchase')->setDescription("Purchase made for {$item}")->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('Payment for $item');
     $redirect_urls = new RedirectUrls();
     $redirect_urls->setReturnUrl(URL::route('api/merchantapi/paypalconfirm'))->setCancelUrl(URL::route('api/merchantapi/paypalcancel'));
     $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;
             }
         }
         //   var_dump($payment->getLinks());
         //   var_dump($redirect_url);
         // add payment ID to session
         Session::put('paypal_payment_id', $payment->getId());
         header('Location: ' . $redirect_url);
         exit;
         //            return isset($redirect_url)?Redirect::away($redirect_url): "Error!!Paypal Checkout 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($cancel_url)->with('alertError', 'Connection error. $err_data');
             exit;
         } else {
             return Redirect::route($cancel_url)->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($cancel_url)->with('alertError', 'Error! ' . $ex->getMessage());
     }
 }