/** * 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; }
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; }
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; }
$cred = new \PayPal\Auth\OAuthTokenCredential("ATbkEXn3uQcX-oP8U9qjvzMrx6fjKB5aRP2nei--_YM0UX8Nq4i6dkdOjn0iw_rPRXnvDJbprf446wlz", "EGMD_Y19KOKXTabyKlHwU1JnNNzUdD8qK_Gv3r1hvHhP33w1CXWkRoukGgViQB9iBHKu0LB6VQL37YUF"); $apiContext = new \PayPal\Rest\ApiContext($cred, 'Request ' . time()); $link = mysqli_connect("localhost", "root", "booksmart", "booksmart"); if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit; } $cardtype = mysqli_real_escape_string($link, $_POST['cardtype']); $cardnumber = mysqli_real_escape_string($link, $_POST['cardnumber']); $cvv = mysqli_real_escape_string($link, $_POST['cvv']); $monthValueParts = explode('-', mysqli_real_escape_string($link, $_POST['expirationmonth'])); $expiryYear = $monthValueParts[0]; $expiryMonth = $monthValueParts[1]; $firstname = mysqli_real_escape_string($link, $_POST['firstname']); $lastname = mysqli_real_escape_string($link, $_POST['lastname']); $creditcard = new \PayPal\Api\CreditCard(); $creditcard->setType($cardtype); $creditcard->setNumber($cardnumber); $creditcard->setExpire_month($expiryMonth); $creditcard->setExpire_year($expiryYear); $creditcard->setCvv2($cvv); $creditcard->setFirst_name($firstname); $creditcard->setLast_name($lastname); try { $creditcard->create($apiContext); //error happens here // echo $creditcard; $_SESSION['CARD_CREATED'] = true; //allows for dynamic display of card creation later header('Location: billing-information.php'); } catch (\PPConnectionException $ex) {
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'); }
<?php require_once 'function.php'; require_once 'sdk/vendor/autoload.php'; // After Step 1 $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AY_WvE4xZOUXLJKLW0sG0CijfhToPVJNZuUr9XpyedhJWEU81tYoWMhQgmxYnm_F-5BZWfEBP2QzuXA6', 'EMEjgxK4lsdgAYL0OAQvzAQ2adyxO9tyD-Ib_7exG2AvQmVX_noXeN_IoQjQK3wxAWbma6jFoA9cCm_3')); // After Step 2 $creditCard = new \PayPal\Api\CreditCard(); $creditCard->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper"); // Step 2.1 : Between Step 2 and Step 3 $apiContext->setConfig(array('log.LogEnabled' => true, 'log.FileName' => 'PayPal.log', 'log.LogLevel' => 'FINE')); // After Step 3 try { $creditCard->create($apiContext); display($creditCard); } catch (\PayPal\Exception\PayPalConnectionException $ex) { // This will print the detailed information on the exception. //REALLY HELPFUL FOR DEBUGGING display($ex->getData()); }
/** * Save a credit card with paypal * * @param array $params credit card parameters */ public function saveCard($payerId, $firstName, $lastName, $ccNumber, $ccExpirationMonth, $ccExpirationYear, $ccCVV, $ccBrandType) { $card = new \PayPal\Api\CreditCard(); $card->setPayerId($payerId); $card->setFirstName($firstName); $card->setLastName($lastName); $card->setType($ccBrandType); $card->setNumber($ccNumber); $card->setExpireMonth($ccExpirationMonth); $card->setExpireYear($ccExpirationYear); $card->setCvv2($ccCVV); $card->create($this->contextFactory->createContext()); return $card->getId(); }
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()); } }
public function paypalApi() { require __DIR__ . '/PayPal-PHP-SDK/autoload.php'; // 2. Provide your Secret Key. Replace the given one with your app clientId, and Secret // https://developer.paypal.com/webapps/developer/applications/myapps $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AZL8y_b5_YMk3t9FFpIK39QA9c7GhF16rG0L4KPbnxclQw36MoQBHB0pIOFndHdgz3Ims3he7pPgB1I-', 'EF0wu84NNCfmnYX3J1aQlGbia15m67pDAmm2kuGXv9-wh69-ofn7Lv_kWcjKzAiE7fxD27oWEHhBzdyp')); // 3. Lets try to save a credit card to Vault using Vault API mentioned here // https://developer.paypal.com/webapps/developer/docs/api/#store-a-credit-card $creditCard = new \PayPal\Api\CreditCard(); $creditCard->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper"); // 4. Make a Create Call and Print the Card try { $creditCard->create($apiContext); echo $creditCard; } catch (\PayPal\Exception\PayPalConnectionException $ex) { // This will print the detailed information on the exception. //REALLY HELPFUL FOR DEBUGGING echo $ex->getData(); } }
$_SESSION['tax_amount'] = isset($_POST['TaxAmount']) && $_POST['TaxAmount'] != '' ? str_replace(",", "", $_POST['TaxAmount']) : '0.00'; $_SESSION['billingInfo'] = isset($_POST['billingInfo']) ? $_POST['billingInfo'] : array(); $_SESSION['shippingInfo'] = isset($_POST['shippingInfo']) ? $_POST['shippingInfo'] : array(); ##########[ Create Payment ]############ // Create new PayPal Api Context $paypal_rest = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential($config['RESTAPIClient_Id'], $config['RESTAPIClient_Secret'])); // Add to header $paypal_rest->addRequestHeader('PayPal-Partner-Attribution-Id', 'AngellEYE_SP_POS_VT'); $addr = new \PayPal\Api\Address(); $addr->setLine1($_SESSION['billing_street1']); $addr->setLine2($_SESSION['billing_street2']); $addr->setCity($_SESSION['billing_city']); $addr->setCountryCode($_SESSION['billing_country_code']); $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)));