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;
}
예제 #2
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;
 }
예제 #3
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');
 }
 $addr->setPostalCode($_SESSION['billing_postal_code']);
 $addr->setState($_SESSION['billing_state']);
 $card = new \PayPal\Api\CreditCard();
 $card->setNumber($_SESSION['cc_number']);
 $card->setType(strtolower($_SESSION['cc_type']));
 $card->setExpireMonth($_SESSION['cc_exp_month']);
 $card->setExpireYear($_SESSION['cc_exp_year']);
 $card->setCvv2($_SESSION['cvv2']);
 $card->setFirstName($_SESSION['billing_first_name']);
 $card->setLastName($_SESSION['billing_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));
 $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();