/**
  * Make paypal Payment via REST API
  *
  */
 public function make_paypal_payment($price, $currencyType, $payment_desc, $card_type, $card_holder_name, $card_number, $expire_month, $expire_year, $cvv)
 {
     $price = (double) $price;
     $card_type = strtolower($card_type);
     // ### CreditCard
     // A resource representing a credit card that can be
     // used to fund a payment.
     $card = new PayPal\Api\CreditCard();
     $card->setType($card_type)->setNumber($card_number)->setExpireMonth("11")->setExpireYear($expire_year)->setCvv2($cvv)->setFirstName($card_holder_name);
     //->setLastName("Shopper");
     // ### FundingInstrument
     // A resource representing a Payer's funding instrument.
     // For direct credit card payments, set the CreditCard
     // field on this object.
     $fi = new PayPal\Api\FundingInstrument();
     $fi->setCreditCard($card);
     // ### Payer
     // A resource representing a Payer that funds a payment
     // For direct credit card payments, set payment method
     // to 'credit_card' and add an array of funding instruments.
     $payer = new PayPal\Api\Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     $amount = new PayPal\Api\Amount();
     $amount->setCurrency($currencyType)->setTotal($price);
     //->setDetails($details);
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it.
     $transaction = new PayPal\Api\Transaction();
     $transaction->setAmount($amount)->setDescription($payment_desc)->setInvoiceNumber(uniqid());
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent set to sale 'sale'
     $payment = new PayPal\Api\Payment();
     $payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
     // For Sample Purposes Only.
     $request = clone $payment;
     // ### Create Payment
     // Create a payment by calling the payment->create() method
     // with a valid ApiContext (See bootstrap.php for more on `ApiContext`)
     // The return object contains the state.
     try {
         $clientId = $this->config->item('clientId');
         $clientSecret = $this->config->item('clientSecret');
         $apiContext = getApiContext($clientId, $clientSecret);
         $payment->create($apiContext);
     } catch (Exception $ex) {
         $this->session->set_flashdata('error_message', 'Something is going wrong! please try again later!!');
         redirect('', 'refresh');
         //ResultPrinter::printError('Create Payment Using Credit Card. If 500 Exception, try creating a new Credit Card using <a href="https://ppmts.custhelp.com/app/answers/detail/a_id/750">Step 4, on this link</a>, and using it.', 'Payment', null, $request, $ex);
         //exit(1);
     }
     //ResultPrinter::printResult('Create Payment Using Credit Card', 'Payment', $payment->getId(), $request, $payment);
     return $payment;
 }
 private function _createPaymentURL(PayPal\Api\Payer $payer, PayPal\Api\RedirectUrls $redirectUrls, PayPal\Api\Transaction $transaction, PayPal\Rest\ApiContext $apiContext)
 {
     $payment = new PayPal\Api\Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($apiContext);
     } catch (Exception $e) {
         CLogger::getInstance()->add(__LINE__, __METHOD__, 'exception error', $e);
         die;
     }
     $url = $payment->getApprovalLink();
     CLogger::getInstance()->add(__LINE__, __METHOD__, 'url paypal', $url);
     CLogger::getInstance()->getLog('PayPal starting checkout');
     header("Location: {$url}");
     exit;
 }
Beispiel #3
0
 public function process()
 {
     $sdkConfig = array("mode" => "sandbox");
     // After Step 1
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AXg9iE-m2XOToUfY4sQ7V1vjQ7cSDnQjiop4aj-M7pgB3hO3ObTYVv8dL51FDkxNsX-Ov8N6p22RD6lS', 'ECRT-ONUf7gq42vbEG1lm9yrbvq1kTXFTCwbQuLiB9TFwZm15KvsBharvgUlR6Dls8sbeaiAWsgsfEHB'));
     $apiContext->setConfig($sdkConfig);
     $this->setDummyState();
     $card_info = $this->getState()->get('card');
     $card = new \PayPal\Api\CreditCard();
     $card->setType($this->getCardType());
     $card->setNumber($card_info->number);
     $card->setExpireMonth($card_info->expire_month);
     $card->setExpireYear($card_info->expire_year);
     $card->setCvv2($card_info->cvv2);
     $fi = new \PayPal\Api\FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod("credit_card");
     $payer->setFundingInstruments(array($fi));
     // Specify the payment amount.
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency('GBP');
     $amount->setTotal($this->getState()->get('transaction.total'));
     // ###Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it. Transaction is created with
     // a `Payee` and `Amount` types
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($this->getState()->get('payment.description'));
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     //  try {
     //      $payment->create($apiContext);
     //  } catch (PayPal\Exception\PayPalConnectionException $ex) {
     //      $this->_error->code = $ex->getCode(); // Prints the Error Code
     //      $this->_error->message = $ex->getData(); // Prints the detailed error message
     //  }
     $this->_payment = $payment;
     $this->status = $this->_payment->getState();
     $this->transaction_id = $payment->transactions[0]->related_resources[0]->sale->id;
     $this->amount = $payment->transactions[0]->amount->total;
     return $this;
 }
function pay_direct_with_credit_card($credit_card_params, $currency, $amount_total, $my_items, $payment_desc)
{
    $card = new PayPal\Api\CreditCard();
    $card->setType($credit_card_params['type']);
    $card->setNumber($credit_card_params['number']);
    $card->setExpireMonth($credit_card_params['expire_month']);
    $card->setExpireYear($credit_card_params['expire_year']);
    $card->setCvv2($credit_card_params['cvv2']);
    $card->setFirstName($credit_card_params['first_name']);
    $card->setLastName($credit_card_params['last_name']);
    $funding_instrument = new PayPal\Api\FundingInstrument();
    $funding_instrument->setCreditCard($card);
    $payer = new PayPal\Api\Payer();
    $payer->setPayment_method("credit_card");
    $payer->setFundingInstruments(array($funding_instrument));
    $amount = new PayPal\Api\Amount();
    $amount->setCurrency($currency);
    $amount->setTotal($amount_total);
    $transaction = new PayPal\Api\Transaction();
    $transaction->setAmount($amount);
    $transaction->setDescription("creating a direct payment with credit card");
    $payment = new PayPal\Api\Payment();
    $payment->setIntent("sale");
    $payment->setPayer($payer);
    $payment->setTransactions(array($transaction));
    $payment->create(apiContext());
    return $payment;
}
Beispiel #5
0
 /**
  * When you have configured the payment properly this will give you a URL that you can redirect your visitor to,
  * so that he can pay the desired amount.
  *
  * @param string $url_format
  * @return string
  */
 public function get_payment_url($url_format)
 {
     if (!is_array($this->payment_provider_auth_config[self::PROVIDER_NAME]) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid']) || !isset($this->payment_provider_auth_config[self::PROVIDER_NAME]['secret'])) {
         throw new \Exception('Auth Config for Provider ' . self::PROVIDER_NAME . ' is not set.', 1394795187);
     }
     $total_price = $this->order->get_total_price();
     if ($total_price == 0) {
         throw new \Exception('Total price is 0. Provider ' . self::PROVIDER_NAME . ' does not support free payments.', 1394795478);
     }
     $api_context = new ApiContext(new OAuthTokenCredential($this->payment_provider_auth_config[self::PROVIDER_NAME]['clientid'], $this->payment_provider_auth_config[self::PROVIDER_NAME]['secret']));
     $api_context->setConfig(array('mode' => 'sandbox', 'http.ConnectionTimeOut' => 30, 'log.LogEnabled' => false));
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     $amount = new Amount();
     $amount->setCurrency("EUR");
     $amount->setTotal($this->order->get_total_price());
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($this->order->get_reason());
     $transaction->setItemList($this->getItemList());
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($this->get_success_url($url_format));
     $redirectUrls->setCancelUrl($this->get_abort_url($url_format));
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $payment->create($api_context);
     $payment_url = '';
     foreach ($payment->getLinks() as $link) {
         /** @var \PayPal\Api\Links $link */
         if ($link->getRel() == 'approval_url') {
             $payment_url = $link->getHref();
         }
     }
     return $payment_url;
 }
Beispiel #6
0
 public function actionStep2()
 {
     // require_once(Yii::getPathOfAlias('application.components.Paypal') . '/autoload.php');
     $this->layoutPath = Yii::getPathOfAlias('webroot') . "/themes/classic/views/layouts";
     $this->layout = 'nonPrepare';
     $this->checkSession(2);
     $request = Yii::app()->request;
     if ($request->isPostRequest && isset($_POST)) {
         try {
             $this->card_number = $this->getPostFilter('card_number');
             $this->card_holder_name = $this->getPostFilter('card_holder_name');
             $this->expiry_year = $this->getPostFilter('expiry_year');
             $this->expiry_month = $this->getPostFilter('expiry_month');
             $this->cvc = $this->getPostFilter('cvc');
             $this->first_name = $this->getPostFilter('first_name');
             $this->last_name = $this->getPostFilter('last_name');
             $this->bill_city = $this->getPostFilter('bill_city');
             $this->bill_address = $this->getPostFilter('bill_address');
             $this->bill_country = $this->getPostFilter('bill_country');
             $this->bill_postcode = $this->getPostFilter('bill_postcode');
             $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential("AZxYt_EVUMu9xXO0DHBHn4KGUVx6UMIdQKAb7QeCek609Zo3lFCAIfIKs29-T4PL66cSoN6189SfoACj", "ELebkFS3jmn9CNu4PF1t8OWaIsHASMDalHKp9x1dwEo0KmeKo582SfeVIC3CC99tmin7NoJZp00jI2Oc"));
             $addr = new \PayPal\Api\Address();
             $addr->setLine1($this->bill_address);
             $addr->setCity($this->bill_city);
             $addr->setCountryCode($this->bill_country);
             $addr->setPostalCode($this->bill_postcode);
             $addr->setState('OH');
             $card = new \PayPal\Api\CreditCard();
             $card->setNumber($this->card_number);
             $card->setType('visa');
             $card->setExpireMonth($this->expiry_month);
             $card->setExpireYear($this->expiry_year);
             $card->setCvv2($this->cvc);
             $card->setFirstName($this->first_name);
             $card->setLastName($this->last_name);
             $card->setBillingAddress($addr);
             $fi = new \PayPal\Api\FundingInstrument();
             $fi->setCreditCard($card);
             $payer = new \PayPal\Api\Payer();
             $payer->setPaymentMethod('credit_card');
             $payer->setFundingInstruments(array($fi));
             $amount = new \PayPal\Api\Amount();
             $amount->setCurrency('USD');
             $amount->setTotal('0.12');
             $transaction = new \PayPal\Api\Transaction();
             $transaction->setAmount($amount);
             $transaction->setDescription('This is the payment transaction description.');
             $redirectUrls = new \PayPal\Api\RedirectUrls();
             $redirectUrls->setReturnUrl(Yii::app()->createAbsoluteUrl('bookService/step3' . '?success=true'))->setCancelUrl(Yii::app()->createAbsoluteUrl('bookService/step3' . '?success=false'));
             $payment = new \PayPal\Api\Payment();
             $payment->setIntent('sale');
             $payment->setPayer($payer);
             $payment->setTransactions(array($transaction));
             try {
                 $res = $payment->create($apiContext);
             } catch (PayPal\Exception\PayPalConnectionException $e) {
                 echo $e->getData();
                 // This will print a JSON which has specific details about the error.
                 // exit(1);
             }
             $this->nextStep(3);
             if (ERunActions::runBackground()) {
                 $this->SendMailConfirm();
             }
             // die();
             $this->redirectStep(3);
         } catch (exception $e) {
             var_dump($e->getMessage());
         }
     }
     $this->render('step2');
 }
Beispiel #7
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
Beispiel #8
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();
 }
Beispiel #9
0
 protected function initializePay($package, $user)
 {
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod('paypal');
     $total = $package->price + $package->tax;
     $item = new \PayPal\Api\Item();
     $item->setName($package->name)->setCurrency('USD')->setQuantity(1)->setPrice($package->price);
     $itemList = new \PayPal\Api\ItemList();
     $itemList->setItems([$item]);
     $details = new \PayPal\Api\Details();
     $details->setTax($package->tax)->setSubtotal($package->price);
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency("USD")->setTotal($total)->setDetails($details);
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($package->name)->setInvoiceNumber(uniqid());
     $baseUrl = "http://trafficmonitor.ca/";
     $redirectUrls = new \PayPal\Api\RedirectUrls();
     $redirectUrls->setReturnUrl($baseUrl . "plan/success")->setCancelUrl($baseUrl . "packages");
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale")->setPayer($payer)->setRedirectUrls($redirectUrls)->setTransactions(array($transaction));
     try {
         $payment->create($this->paypal());
         $transaction = new Transaction(array("user_id" => $user->id, "property" => "package", "property_id" => $package->id, "payment_id" => $payment->getId(), "amount" => $total));
         $transaction->save();
     } catch (Exception $e) {
         die($e);
     }
     return $approvalUrl = $payment->getApprovalLink();
 }
Beispiel #10
0
 public function credit_card()
 {
     $card = new \PayPal\Api\CreditCard();
     $card->setType($this->card_type)->setNumber($this->card_number)->setExpireMonth($this->card_month)->setExpireYear($this->card_year)->setCvv2($this->card_cvv)->setFirstName($this->card_fname)->setLastName($this->card_lname);
     $fi = new \PayPal\Api\FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod('credit_card')->setFundingInstruments(array($fi));
     $items = array();
     foreach ($this->items as $item) {
         $item2 = new \PayPal\Api\Item();
         $item2->setName($item[0])->setDescription($item[1])->setCurrency(CURRENCY)->setQuantity($item[2])->setPrice($item[3]);
         $items[] = $item2;
     }
     $itemList = new \PayPal\Api\ItemList();
     $itemList->setItems($items);
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency(CURRENCY)->setTotal($this->total);
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($this->description);
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent($this->intent)->setPayer($payer)->setTransactions(array($transaction));
     try {
         $payment->create($this->apiContext);
         return array('id' => $payment->getId(), 'total' => $this->total, 'items' => $this->items, 'details' => $this->description, 'state' => $payment->getstate());
     } catch (Exception $e) {
         throw new \Exception('PayPal error: ' . $e->getMessage());
     }
 }
 $payer->setFundingInstruments(array($fi));
 $amountDetails = new \PayPal\Api\Details();
 $amountDetails->setSubtotal(str_replace(",", "", number_format($_SESSION['subtotal'], 2)));
 $amountDetails->setTax(str_replace(",", "", number_format($_SESSION['tax_amount'], 2)));
 $amountDetails->setShipping(str_replace(",", "", number_format($_SESSION['shipping_amount'], 2)));
 $amountDetails->setHandlingFee(str_replace(",", "", number_format($_SESSION['handling_amount'], 2)));
 $amount = new \PayPal\Api\Amount();
 $amount->setCurrency(isset($config['CurrencyCode']) ? $config['CurrencyCode'] : 'USD');
 $amount->setTotal(str_replace(",", "", number_format($_SESSION['amount'], 2)));
 $amount->setDetails($amountDetails);
 $transaction = new \PayPal\Api\Transaction();
 $transaction->setAmount($amount);
 $transaction->setDescription(isset($_SESSION['item_name']) && $_SESSION['item_name'] != '' ? $_SESSION['item_name'] : 'PayPal Payments Pro Virtual Terminal Sale');
 $transaction->setInvoiceNumber($_SESSION['invoice']);
 $transaction->setCustom($_SESSION['notes']);
 $payment = new \PayPal\Api\Payment();
 $payment->setIntent(strtolower($_SESSION['transaction_type']));
 $payment->setPayer($payer);
 $payment->setTransactions(array($transaction));
 try {
     $payment->create($paypal_rest);
     if ($payment->getState() == 'approved') {
         $transactions = $payment->getTransactions();
         foreach ($transactions as $txn) {
             $related_resources = $txn->getRelatedResources();
             foreach ($related_resources as $related) {
                 $related_sale = $related->getSale();
                 if ($related_sale) {
                     $_SESSION['transaction_id'] = $related_sale->id;
                 }
             }
Beispiel #12
0
     }
     $apiContext = new \PayPal\Rest\ApiContext($cred, 'Request' . time());
     $apiContext->setConfig($sdkConfig);
     $payer = new \PayPal\Api\Payer();
     $payer->setPaymentMethod("paypal");
     $amount = new \PayPal\Api\Amount();
     $amount->setCurrency("EUR");
     $amount->setTotal("{$price}");
     $transaction = new \PayPal\Api\Transaction();
     $transaction->setDescription("Deine Bestellung bei Alma Mater Wear");
     $transaction->setAmount($amount);
     //$baseUrl = getBaseUrl();
     $redirectUrls = new \PayPal\Api\RedirectUrls();
     $redirectUrls->setReturnUrl($success_url);
     $redirectUrls->setCancelUrl($error_url);
     $payment = new \PayPal\Api\Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setRedirectUrls($redirectUrls);
     $payment->setTransactions(array($transaction));
     $payment->create($apiContext);
     //Nach erfolgreicher Bezahlung wird der Bezahlstatus auf 1 gesetzt. Dafür wird die Payment ID in der Datenbank gespeichert
     mysqli_query($link, "UPDATE orders SET paymentID = '{$payment->id}' WHERE id = {$orderId}");
     //Der Ziellink wird ausgegeben und per JavaScript geöffnet
     $referer = $payment->links[1]->href;
     echo $referer;
 } else {
     if (USE_LIVE_PAYMENT) {
         //in live mode, Sofort is currently locked.
         echo "Order cancelled";
     } else {