setType() public method

Credit card type. Valid types are: visa, mastercard, discover, amex
public setType ( string $type )
$type string
コード例 #1
0
ファイル: Paypal.php プロジェクト: shinomontaz/yii2-paypal
 /**
  * Runs a card payment with PayPal
  *
  * @link https://devtools-paypal.com/guide/pay_creditcard/php?interactive=ON&env=sandbox
  * @return PayPal\Api\Payment 
  */
 public function payCard($cardInfo = [], $sum = 0, $message = '')
 {
     $card = new CreditCard();
     $card->setType($cardInfo['cardType']);
     $card->setNumber($cardInfo['cardNumber']);
     $card->setExpireMonth($cardInfo['expMonth']);
     $card->setExpireYear($cardInfo['expYear']);
     $card->setFirstName($cardInfo['firstName']);
     $card->setLastName($cardInfo['lastName']);
     $fundingInstrument = new FundingInstrument();
     $fundingInstrument->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod('credit_card');
     $payer->setFundingInstruments(array($fundingInstrument));
     $amount = new Amount();
     $amount->setCurrency($this->currency);
     $amount->setTotal($sum);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     if ($message) {
         $transaction->setDescription($message);
     }
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     return $payment->create($this->_apiContext);
     // get state from this json
 }
コード例 #2
0
ファイル: Driver.php プロジェクト: breadphp/paypal
 public static function preparePayment($payment, $domain)
 {
     $items = array();
     $currency = null;
     $total = 0;
     foreach ($payment->items as $item) {
         $tmpItem = new PayPalItem();
         $tmpItem->setName($item->description)->setCurrency($item->currency)->setQuantity($item->quantity)->setSku($item->sku)->setPrice($item->price);
         $items[] = $tmpItem;
         //
         $total += (double) $item->price;
         $currency = $item->currency;
     }
     $itemList = new ItemList();
     $itemList->setItems($items);
     $payer = new PayPalPayer();
     switch ($payment->payer->paymentMethod) {
         case Payer::PAYMENT_CREDIT_CARD:
             $payer->setPaymentMethod($payment->payer->paymentMethod);
             $card = new PayPalCreditCard();
             $card->setType($payment->payer->creditCard->type)->setNumber($payment->payer->creditCard->number)->setExpireMonth($payment->payer->creditCard->expireMonth)->setExpireYear($payment->payer->creditCard->expireYear)->setCvv2($payment->payer->creditCard->cvv2)->setFirstName($payment->payer->creditCard->firstName)->setLastName($payment->payer->creditCard->lastName);
             $fi = new FundingInstrument();
             $fi->setCreditCard($card);
             $payer->setFundingInstruments(array($fi));
             break;
         case Payer::PAYMENT_PAYPAL:
             $payer->setPaymentMethod($payment->payer->paymentMethod);
             break;
     }
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($total);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription($payment->description);
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($payment->returnUrl);
     $redirectUrls->setCancelUrl($payment->cancelUrl);
     $paypalPayment = new PayPalPayment();
     $paypalPayment->setRedirectUrls($redirectUrls);
     $paypalPayment->setIntent($payment->intent);
     $paypalPayment->setPayer($payer);
     $paypalPayment->setTransactions(array($transaction));
     try {
         $paypalPayment->create(static::getApiContext($domain));
         return static::getPayment($paypalPayment->getId(), $domain)->then(function ($payment) use($paypalPayment) {
             $payment->approvalUrl = static::getLink($paypalPayment->getLinks(), "approval_url");
             return $payment;
         });
     } catch (PayPalConnectionException $e) {
         return When::reject($e);
     } catch (PayPalInvalidCredentialException $e) {
         return When::reject($e);
     }
 }
コード例 #3
0
ファイル: Paypal.php プロジェクト: shivap87/cost
 /**
  * Save a credit card with paypal
  * 
  * This helps you avoid the hassle of securely storing credit
  * card information on your site. PayPal provides a credit card
  * id that you can use for charging future payments.
  * 
  * @param array $params	credit card parameters
  */
 function saveCard($params)
 {
     $card = new CreditCard();
     $card->setType($params['type']);
     $card->setNumber($params['number']);
     $card->setExpireMonth($params['expire_month']);
     $card->setExpireYear($params['expire_year']);
     $card->setCvv2($params['cvv2']);
     $card->create(getApiContext());
     return $card->getId();
 }
コード例 #4
0
ファイル: CardForm.php プロジェクト: Lucerin/Yii-projects
 public function doStoreCreditCardAPI($payment_type, $card_number, $exp_month, $exp_year, $csc, $first_name, $last_name)
 {
     $apiContext = new ApiContext(new OAuthTokenCredential(self::CLIENT_ID, self::SECRET));
     $card = new CreditCard();
     $card->setType($payment_type);
     $card->setNumber($card_number);
     $card->setExpire_month($exp_month);
     $card->setExpire_year($exp_year);
     $card->setCvv2($csc);
     $card->setFirst_name($first_name);
     $card->setLast_name($last_name);
     try {
         $card->create($apiContext);
         //$card->create($apiContext);
     } catch (\PPConnectionException $ex) {
         echo "Exception:" . $ex->getMessage() . PHP_EOL;
         var_dump($ex->getData());
         exit(1);
     }
     //            $test = $card->getId();
     //
     //            $creditCardToken = new CreditCardToken();
     //            $creditCardToken->setCredit_card_id($test);
     //
     //            $fundingInstrument = new FundingInstrument();
     //            $fundingInstrument->setCredit_card($creditCardToken);
     //
     //            $payer = new Payer();
     //            $payer->setPayment_method("credit_card");
     //            $payer->setFunding_instruments(array($fundingInstrument));
     //
     //            $amount = new Amount();
     //            $amount->setCurrency("USD");
     //            $amount->setTotal($total);
     //
     //            $transaction = new Transaction();
     //            $transaction->setAmount($amount);
     //            $transaction->setDescription("creating a direct payment with credit card");
     //
     //            $payment = new Payment();
     //            $payment->setIntent("sale");
     //            $payment->setPayer($payer);
     //            $payment->setTransactions(array($transaction));
     //
     //            try {
     //                $payment->create($apiContext);    //$card->create($apiContext);
     //            } catch (\PPConnectionException $ex) {
     //                echo "Exception:" . $ex->getMessage() . PHP_EOL;
     //                var_dump($ex->getData());
     //                exit(1);
     //            }
     return $card->getId();
 }
コード例 #5
0
 public static function createCreditCard()
 {
     $card = new CreditCard();
     $card->setType(self::$cardType);
     $card->setNumber(self::$cardNumber);
     $card->setExpireMonth(self::$expireMonth);
     $card->setExpireYear(self::$expireYear);
     $card->setCvv2(self::$cvv);
     $card->setFirstName(self::$firstName);
     $card->setLastName(self::$lastName);
     $card->setPayerId(self::$payerId);
     return $card;
 }
コード例 #6
0
 public static function createCreditCard()
 {
     $card = new CreditCard();
     $card->setType(self::$cardType);
     $card->setNumber(self::$cardNumber);
     $card->setExpireMonth(self::$expireMonth);
     $card->setExpireYear(self::$expireYear);
     $card->setCvv2(self::$cvv);
     $card->setFirstName(self::$firstName);
     $card->setLastName(self::$lastName);
     $card->setId(self::$id);
     $card->setValidUntil(self::$validUntil);
     $card->setState(self::$state);
     return $card;
 }
コード例 #7
0
ファイル: Gateway.php プロジェクト: aliuadepoju/hqpay
 function paypal($data)
 {
     try {
         foreach ($data as $k => $v) {
             ${$k} = $v;
         }
         include_once 'config.paypal.php';
         $apiContext = new ApiContext(new OAuthTokenCredential(CLIENT_ID, CLIENT_SECRET));
         list($m, $y) = explode("/", $card_expiry);
         $card = new CreditCard();
         $card->setNumber($card_number);
         $card->setType(strtolower($card_type));
         $card->setExpireMonth($m);
         $card->setExpireYear($y);
         $card->setCvv2($card_cvv);
         $card->setFirstName($first_name);
         $card->setLastName($last_name);
         $fi = new FundingInstrument();
         $fi->setCreditCard($card);
         $payer = new Payer();
         $payer->setPaymentMethod('credit_card');
         $payer->setFundingInstruments(array($fi));
         $amount = new Amount();
         $amount->setCurrency($currency);
         $amount->setTotal($price);
         $transaction = new Transaction();
         $transaction->setAmount($amount);
         $transaction->setDescription('Enter your card details and proceed');
         $payment = new Payment();
         $payment->setIntent('sale');
         $payment->setPayer($payer);
         $payment->setTransactions(array($transaction));
         $res = json_decode($payment->create($apiContext));
         $this->save($data, __FUNCTION__, $res, 1);
         return json_encode(["status" => true, "msg" => sprintf("Your payment has been %s", $res->state)]);
     } catch (Exception $e) {
         if ($e instanceof PPConfigurationException) {
         } elseif ($e instanceof PPConnectionException) {
         } elseif ($e instanceof PayPal\Exception\PayPalConnectionException) {
             $res = json_decode($e->getData(), 1);
             $this->save($data, __FUNCTION__, $res, 0);
             $msg = array_shift(isset($res["details"]) ? $res["details"] : []);
             return json_encode(["status" => false, "msg" => $res["name"] == "UNKNOWN_ERROR" || empty($msg["issue"]) ? "An unknown error has occurred" : sprintf("%s %s", ["cvv2" => "CVV2", "expire_year" => "Card expiration", "credit_card" => "", "type" => "Invalid credit card number or", "number" => "Credit card number", "expire_month" => "Expiration month"][end(explode(".", $msg["field"]))], strtolower($msg["issue"]))]);
         } else {
             throw $e;
         }
     }
 }
コード例 #8
0
ファイル: Paypalnew.php プロジェクト: ewwgit/eptri
 public function payDemo()
 {
     $this->authorize();
     $addr = new Address();
     $addr->setLine1('52 N Main ST');
     $addr->setCity('Johnstown');
     $addr->setCountryCode('US');
     $addr->setPostalCode('43210');
     $addr->setState('OH');
     $card = new CreditCard();
     $card->setNumber('4417119669820331');
     $card->setType('visa');
     $card->setExpireMonth('11');
     $card->setExpireYear('2018');
     $card->setCvv2('874');
     $card->setFirstName('Joe');
     $card->setLastName('Shopper');
     $card->setBillingAddress($addr);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod('credit_card');
     $payer->setFundingInstruments(array($fi));
     $amountDetails = new \PayPal\Api\Details();
     $amountDetails->setSubtotal('7.41');
     $amountDetails->setTax('0.03');
     $amountDetails->setShipping('0.03');
     $amount = new Amount();
     $amount->setCurrency('USD');
     $amount->setTotal('7.47');
     $amount->setDetails($amountDetails);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription('This is the payment transaction description.');
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $payment->create($this->_apiContext);
 }
コード例 #9
0
ファイル: common.php プロジェクト: bjrambo/nurigo
/**
 * Creates a new mock 'payment authorization'
 *
 * @param PayPal\Api\ApiContext apiContext
 * @return PayPal\Api\Authorization
 */
function createAuthorization($apiContext)
{
    $addr = new Address();
    $addr->setLine1("3909 Witmer Road")->setLine2("Niagara Falls")->setCity("Niagara Falls")->setState("NY")->setPostalCode("14305")->setCountryCode("US")->setPhone("716-298-1822");
    $card = new CreditCard();
    $card->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper")->setBillingAddress($addr);
    $fi = new FundingInstrument();
    $fi->setCreditCard($card);
    $payer = new Payer();
    $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
    $amount = new Amount();
    $amount->setCurrency("USD")->setTotal("1.00");
    $transaction = new Transaction();
    $transaction->setAmount($amount)->setDescription("Payment description.");
    $payment = new Payment();
    // Setting intent to authorize creates a payment
    // authorization. Setting it to sale creates actual payment
    $payment->setIntent("authorize")->setPayer($payer)->setTransactions(array($transaction));
    $paymnt = $payment->create($apiContext);
    $resArray = $paymnt->toArray();
    return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
}
コード例 #10
0
 public static function authorize()
 {
     $addr = new Address();
     $addr->setLine1("3909 Witmer Road");
     $addr->setLine2("Niagara Falls");
     $addr->setCity("Niagara Falls");
     $addr->setState("NY");
     $addr->setPostal_code("14305");
     $addr->setCountry_code("US");
     $addr->setPhone("716-298-1822");
     $card = new CreditCard();
     $card->setType("visa");
     $card->setNumber("4417119669820331");
     $card->setExpire_month("11");
     $card->setExpire_year("2019");
     $card->setCvv2("012");
     $card->setFirst_name("Joe");
     $card->setLast_name("Shopper");
     $card->setBilling_address($addr);
     $fi = new FundingInstrument();
     $fi->setCredit_card($card);
     $payer = new Payer();
     $payer->setPayment_method("credit_card");
     $payer->setFunding_instruments(array($fi));
     $amount = new Amount();
     $amount->setCurrency("USD");
     $amount->setTotal("1.00");
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription("This is the payment description.");
     $payment = new Payment();
     $payment->setIntent("authorize");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $paymnt = $payment->create();
     $resArray = $paymnt->toArray();
     return $authId = $resArray['transactions'][0]['related_resources'][0]['authorization']['id'];
 }
コード例 #11
0
ファイル: DeleteCreditCard.php プロジェクト: ewwgit/eptri
<?php

// # Delete CreditCard Sample
// This sample code demonstrate how you can
// delete a saved credit card.
// API used: /v1/vault/credit-card/{<creditCardId>}
// NOTE: HTTP method used here is DELETE
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard;
// Store a mock card that can be deleted later.
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard();
$card->setType("visa")->setNumber("4417119669820331")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
// ### Save card
// Creates the credit card as a resource
// in the PayPal vault. The response contains
// an 'id' that you can use to refer to it later.
// (See bootstrap.php for more on `ApiContext`)
try {
    $card = $card->create($apiContext);
} catch (PayPal\Exception\PPConnectionException $ex) {
    echo "Exception:" . $ex->getMessage() . PHP_EOL;
    var_dump($ex->getData());
    exit(1);
}
try {
    // ### Delete Card
    // Lookup and delete a saved credit card.
    // (See bootstrap.php for more on `ApiContext`)
コード例 #12
0
        ]
    }
}*/
$agreement = new Agreement();
$agreement->setName('DPRP')->setDescription('Payment with credit Card')->setStartDate('2015-06-17T9:45:04Z');
// Add Plan ID
// Please note that the plan Id should be only set in this case.
$plan = new Plan();
$plan->setId($createdPlan->getId());
$agreement->setPlan($plan);
// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('credit_card')->setPayerInfo(new PayerInfo(array('email' => '*****@*****.**')));
// Add Credit Card to Funding Instruments
$creditCard = new CreditCard();
$creditCard->setType('visa')->setNumber('4417119669820331')->setExpireMonth('12')->setExpireYear('2017')->setCvv2('128');
$fundingInstrument = new FundingInstrument();
$fundingInstrument->setCreditCard($creditCard);
$payer->setFundingInstruments(array($fundingInstrument));
//Add Payer to Agreement
$agreement->setPayer($payer);
// Add Shipping Address
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')->setCity('Saratoga')->setState('CA')->setPostalCode('95070')->setCountryCode('US');
$agreement->setShippingAddress($shippingAddress);
// For Sample Purposes Only.
$request = clone $agreement;
// ### Create Agreement
try {
    // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
    $agreement = $agreement->create($apiContext);
コード例 #13
0
 /**
  * @param $data     array       form post data
  * @return string   HTML to display
  */
 function _prePayment($data)
 {
     $this->_autoload();
     $order = $this->_getOrder($data['order_number']);
     //initialise application
     $app = JFactory::getApplication();
     //get card input
     $data['cardtype'] = $app->input->getString("cardtype");
     $data['cardnum'] = $app->input->getString("cardnum");
     $month = $app->input->getString("month");
     $year = $app->input->getString("year");
     $card_exp = $month . '' . $year;
     $data['cardexp'] = $card_exp;
     $data['cardcvv'] = $app->input->getString("cardcvv");
     $data['cardnum_last4'] = substr($app->input->getString("cardnum"), -4);
     //initialise payment
     $apiContext = new ApiContext(new OAuthTokenCredential($this->api_clientId, $this->api_clientSecret));
     $apiContext->setConfig(array('mode' => $this->api_mode));
     //		echo'<pre>';print_r($apiContext);die;
     $card = new CreditCard();
     $card->setType($data['cardtype']);
     $card->setNumber($data['cardnum']);
     $card->setExpireMonth($month);
     $card->setExpireYear($year);
     $card->setFirstName($data['firstname']);
     $card->setLastName($data['lastname']);
     $card->setCvv2($data['cardcvv']);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     if (!empty($data['email'])) {
         $payerInfo = new PayerInfo();
         $payerInfo->setFirstName($data['firstname']);
         $payerInfo->setLastName($data['lastname']);
         $payerInfo->setEmail($data['email']);
         $payer->setPayerInfo($payerInfo);
     }
     $amount = new Amount();
     $amount->setCurrency($this->currency);
     $amount->setTotal($data['total']);
     $item1 = new Item();
     $item1->setName($data['order_number'])->setDescription($data['order_number'])->setCurrency($this->currency)->setQuantity(1)->setTax(0)->setPrice($data['total']);
     $itemList = new ItemList();
     $itemList->setItems(array($item1));
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setItemList($itemList);
     $transaction->setDescription($data['order_number']);
     $payment = new Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $request = clone $payment;
     try {
         $payment->create($apiContext);
     } catch (PayPal\Exception\PayPalConnectionException $ex) {
         $error = json_decode($ex->getData());
         $error_html = '<h2>' . $error->name . '</h2><br>';
         foreach ($error->details as $r) {
             $error_html .= '- ' . $r->field . ' - ' . $r->issue . '<br>';
         }
         $app->enqueueMessage($error_html, 'error');
         $app->redirect('index.php?option=com_bookpro&view=formpayment&order_id=' . $order->id . '&' . JSession::getFormToken() . '=1');
         return;
     } catch (Exception $ex) {
         die($ex);
     }
     $ack = $payment->getState();
     if ($ack == 'approved' || $ack == 'completed') {
         $order->pay_status = "SUCCESS";
         $order->order_status = "CONFIRMED";
         $order->tx_id = $payment->getId();
         $order->store();
     } else {
         JLog::addLogger(array('text_file' => 'paypal.txt', 'text_file_path' => 'logs', 'text_file_no_php' => 1, 'text_entry_format' => '{DATE} {TIME} {MESSAGE}'), JLog::ALERT);
         JLog::add('Transaction: ' . json_encode($payment) . '\\nOrder: ' . $order->order_number . ' Status: ' . $ack, JLog::ALERT, 'com_bookpro');
         $order->pay_status = "PENDING";
         $order->tx_id = $transaction_id;
         $order->store();
     }
     $app = JFactory::getApplication();
     $app->redirect('index.php?option=com_bookpro&controller=payment&task=postpayment&method=' . $this->_element . '&order_number=' . $order->order_number);
     return;
 }
コード例 #14
0
ファイル: CreatePayment.php プロジェクト: jackyFeng/unisol
$card = new CreditCard();
//$card->setType("visa")
//   ->setNumber("4148529247832259")
//    ->setExpireMonth("11")
//    ->setExpireYear("2019")
//    ->setCvv2("012")
//   ->setFirstName("Joe")
//    ->setLastName("Shopper");
$creditcard_type = $_POST["creditcard"];
$cardHolderFN = filter_input(INPUT_POST, 'cardHolderFN');
$cardHolderLN = filter_input(INPUT_POST, 'cardHolderLN');
$cardNumber = filter_input(INPUT_POST, 'cardNumber');
$expMonth = filter_input(INPUT_POST, 'expMonth');
$expYear = filter_input(INPUT_POST, 'expYear');
$cvCode = filter_input(INPUT_POST, 'cvCode');
$card->setType($creditcard_type)->setNumber($cardNumber)->setExpireMonth($expMonth)->setExpireYear($expYear)->setCvv2($cvCode)->setFirstName($cardHolderFN)->setLastName($cardHolderLN);
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// For direct credit card payments, set the CreditCard
// field on this object.
$fi = new 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 Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise
// information
コード例 #15
0
 public function postPayment()
 {
     $paypal_conf = Config::get('paypal');
     $apiContext = new ApiContext(new OAuthTokenCredential($paypal_conf['client_id'], $paypal_conf['secret']));
     $apiContext->setConfig($paypal_conf['settings']);
     $card = new CreditCard();
     $card->setType("visa")->setNumber("4148529247832259")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     $item1 = new Item();
     $item1->setName('Ground Coffee 40 oz')->setDescription('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setTax(0.3)->setPrice(7.5);
     $item2 = new Item();
     $item2->setName('Granola bars')->setDescription('Granola Bars with Peanuts')->setCurrency('USD')->setQuantity(5)->setTax(0.2)->setPrice(2);
     $itemList = new ItemList();
     $itemList->setItems(array($item1, $item2));
     $details = new Details();
     $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
     $amount = new Amount();
     $amount->setCurrency("USD")->setTotal(20)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         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);
     var_dump($payment);
     echo "string";
     /*exit;
             $payer = new Payer();
             $payer->setPaymentMethod('paypal');
     
             $item_1 = new Item();
             $item_1->setName('Item 1') // item name
                 ->setCurrency('USD')
                 ->setQuantity(2)
                 ->setPrice('15'); // unit price
     
             $item_2 = new Item();
             $item_2->setName('Item 2')
                 ->setCurrency('USD')
                 ->setQuantity(4)
                 ->setPrice('7');
     
             $item_3 = new Item();
             $item_3->setName('Item 3')
                 ->setCurrency('USD')
                 ->setQuantity(1)
                 ->setPrice('20');
     
             // add item to list
             $item_list = new ItemList();
             $item_list->setItems(array($item_1, $item_2, $item_3));
     
             $amount = new Amount();
             $amount->setCurrency('USD')
                 ->setTotal(78);
     
             $transaction = new Transaction();
             $transaction->setAmount($amount)
                 ->setItemList($item_list)
                 ->setDescription('Your transaction description');
     
             $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 occur, 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 Redirect::route('original.route')
                 ->with('error', 'Unknown error occurred');*/
 }
コード例 #16
0
ファイル: CreateCreditCard.php プロジェクト: Roc4rdho/app
<?php

// # Create Credit Card Sample
// You can store credit card details securely
// with PayPal. You can then use the returned
// Credit card id to process future payments.
// API used: POST /v1/vault/credit-card
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\CreditCard;
// ### CreditCard
// A resource representing a credit card that is
// to be stored with PayPal.
$card = new CreditCard();
$card->setType("visa")->setNumber("4917912523797702")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
// ### Additional Information
// Now you can also store the information that could help you connect
// your users with the stored credit cards.
// All these three fields could be used for storing any information that could help merchant to point the card.
// However, Ideally, MerchantId could be used to categorize stores, apps, websites, etc.
// ExternalCardId could be used for uniquely identifying the card per MerchantId. So, combination of "MerchantId" and "ExternalCardId" should be unique.
// ExternalCustomerId could be userId, user email, etc to group multiple cards per user.
$card->setMerchantId("MyStore1");
$card->setExternalCardId("CardNumber123" . uniqid());
$card->setExternalCustomerId("*****@*****.**");
// For Sample Purposes Only.
$request = clone $card;
// ### Save card
// Creates the credit card as a resource
// in the PayPal vault. The response contains
// an 'id' that you can use to refer to it
// in future payments.
コード例 #17
0
ファイル: test.php プロジェクト: paydunk/paypal
// API used: /v1/payments/payment
require __DIR__ . '/PayPalSDK/paypal/rest-api-sdk-php/sample/bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard();
$card->setType($card_type)->setNumber($card_number)->setExpireMonth($month)->setExpireYear($year)->setCvv2($cvv);
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// For direct credit card payments, set the CreditCard
// field on this object.
$fi = new 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 Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
// ### Additional payment details
// Use this optional field to set additional
// payment information such as tax, shipping
コード例 #18
0
 public function teszt($amount, $description)
 {
     $apiContext = new \PayPal\Rest\ApiContext(new \PayPal\Auth\OAuthTokenCredential('AfikH2WfU1x0YF1ThuSkBaMKqDh-rxE5NEBpLWOF3UVmii-P97WdgJCUhoH1ff5pMHToHnB-sXoejgGv', 'EM7ObD_onQ1EqaeiVBFvSId9AIQevTlsYcLPi-3SeVivyQ9A361Ov5jx4KlFkamOsh_c6I25VM1Ck4ZX'));
     //SAMPLE 1
     // $card = new CreditCard();
     // $card->setType("visa")
     //     ->setNumber("4148529247832259")
     //     ->setExpireMonth("11")
     //     ->setExpireYear("2019")
     //     ->setCvv2("012")
     //     ->setFirstName("Joe")
     //     ->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 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 Payer();
     // $payer->setPaymentMethod("credit_card")
     //     ->setFundingInstruments(array($fi));
     // // ### Itemized information
     // // (Optional) Lets you specify item wise
     // // information
     // $item1 = new Item();
     // $item1->setName('Ground Coffee 40 oz')
     //     ->setDescription('Ground Coffee 40 oz')
     //     ->setCurrency('USD')
     //     ->setQuantity(1)
     //     ->setTax(0.3)
     //     ->setPrice(7.50);
     // $item2 = new Item();
     // $item2->setName('Granola bars')
     //     ->setDescription('Granola Bars with Peanuts')
     //     ->setCurrency('USD')
     //     ->setQuantity(5)
     //     ->setTax(0.2)
     //     ->setPrice(2);
     // $itemList = new ItemList();
     // $itemList->setItems(array($item1, $item2));
     // // ### Additional payment details
     // // Use this optional field to set additional
     // // payment information such as tax, shipping
     // // charges etc.
     // $details = new Details();
     // $details->setShipping(1.2)
     //     ->setTax(1.3)
     //     ->setSubtotal(17.5);
     // // ### Amount
     // // Lets you specify a payment amount.
     // // You can also specify additional details
     // // such as shipping, tax.
     // $amount = new Amount();
     // $amount->setCurrency("USD")
     //     ->setTotal(20)
     //     ->setDetails($details);
     // // ### Transaction
     // // A transaction defines the contract of a
     // // payment - what is the payment for and who
     // // is fulfilling it.
     // $transaction = new Transaction();
     // $transaction->setAmount($amount)
     //     ->setItemList($itemList)
     //     ->setDescription("Payment description")
     //     ->setInvoiceNumber(uniqid());
     // // ### Payment
     // // A Payment Resource; create one using
     // // the above types and intent set to sale 'sale'
     // $payment = new 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 {
     //     $payment->create($apiContext);
     // } catch (Exception $ex) {
     //    // 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;
     //END SAMPLE 1
     //SAMPLE 2
     // $creditCard = new \PayPal\Api\CreditCard();
     // $creditCard->setType("visa")
     //     ->setNumber("4417119669820331")
     //     ->setExpireMonth("11")
     //     ->setExpireYear("2019")
     //     ->setCvv2("012")
     //     ->setFirstName("Joe")
     //     ->setLastName("Shopper");
     // try {
     //     $creditCard->create($apiContext);
     //     echo '<pre>';
     //     print_r($creditCard);
     // }
     // catch (\PayPal\Exception\PayPalConnectionException $ex) {
     //     echo $ex;
     // }
     //END SAMPLE 2
     //SAMPLE 3
     $payer = new Payer();
     $payer->setPaymentMethod("paypal");
     // ### Itemized information
     // (Optional) Lets you specify item wise
     // information
     $item1 = new Item();
     $item1->setName('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setPrice(7.5);
     $item2 = new Item();
     $item2->setName('Granola bars')->setCurrency('USD')->setQuantity(5)->setPrice(2);
     $itemList = new ItemList();
     $itemList->setItems(array($item1, $item2));
     // ### Additional payment details
     // Use this optional field to set additional
     // payment information such as tax, shipping
     // charges etc.
     /* $details = new Details();
     $details->setShipping(1.2)
         ->setTax(1.3)
         ->setSubtotal(17.50); */
     // ### Amount
     // Lets you specify a payment amount.
     // You can also specify additional details
     // such as shipping, tax.
     /* $amount = new Amount();
     $amount->setCurrency("USD")
         ->setTotal(20)
         ->setDetails($details); */
     // ### Transaction
     // A transaction defines the contract of a
     // payment - what is the payment for and who
     // is fulfilling it.
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description");
     // ->setInvoiceNumber('134');
     //>setInvoiceNumber(uniqid());
     // ### Redirect urls
     // Set the urls that the buyer must be redirected to after
     // payment approval/ cancellation.
     //$baseUrl = getBaseUrl();
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/ordered")->setCancelUrl("http://localhost/yii-application/frontend/web/index.php?r=/cart/default/index");
     // ### Payment
     // A Payment Resource; create one using
     // the above types and intent set to 'sale'
     /* $payment = new Payment();
     $payment->setIntent("sale")
         ->setPayer($payer)
         ->setRedirectUrls($redirectUrls)
         ->setTransactions(array($transaction)); */
     $addr = new Address();
     $addr->setLine1('52 N Main ST');
     $addr->setCity('Johnstown');
     $addr->setCountryCode('US');
     $addr->setPostalCode('43210');
     $addr->setState('OH');
     $card = new CreditCard();
     $card->setNumber('5110929378020149');
     $card->setType('MASTERCARD');
     $card->setExpireMonth('08');
     $card->setExpireYear('2020');
     $card->setCvv2('874');
     $card->setFirstName('Nishanth');
     $card->setLastName('Pininti');
     $card->setBillingAddress($addr);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod('credit_card');
     $payer->setFundingInstruments(array($fi));
     $amountDetails = new \PayPal\Api\Details();
     $amountDetails->setSubtotal('7.41');
     $amountDetails->setTax('0.03');
     $amountDetails->setShipping('0.03');
     $amount = new Amount();
     $amount->setCurrency('USD');
     $amount->setTotal('7.47');
     $amount->setDetails($amountDetails);
     $transaction = new Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription('This is the payment transaction description.');
     $payment = new Payment();
     $payment->setIntent('sale');
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     // For Sample Purposes Only.
     $request = clone $payment;
     // ### Create Payment
     // Create a payment by calling the 'create' method
     // passing it a valid apiContext.
     // (See bootstrap.php for more on `ApiContext`)
     // The return object contains the state and the
     // url to which the buyer must be redirected to
     // for payment approval
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
         exit(1);
     }
     // ### Get redirect url
     // The API response provides the url that you must redirect
     // the buyer to. Retrieve the url from the $payment->getApprovalLink()
     // method
     //$approvalUrl = $payment->getRedirectUrls();
     // ResultPrinter::printResult("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
     var_dump($payment);
     return $payment;
     //END SAMPLE 3
 }
        ]
    }
}*/
$agreement = new Agreement();
$agreement->setName('DPRP')->setDescription('Payment with credit Card')->setStartDate('2015-06-17T9:45:04Z');
// Add Plan ID
// Please note that the plan Id should be only set in this case.
$plan = new Plan();
$plan->setId($createdPlan->getId());
$agreement->setPlan($plan);
// Add Payer
$payer = new Payer();
$payer->setPaymentMethod('credit_card')->setPayerInfo(new PayerInfo(array('email' => '*****@*****.**')));
// Add Credit Card to Funding Instruments
$creditCard = new CreditCard();
$creditCard->setType('visa')->setNumber('4491759698858890')->setExpireMonth('12')->setExpireYear('2017')->setCvv2('128');
$fundingInstrument = new FundingInstrument();
$fundingInstrument->setCreditCard($creditCard);
$payer->setFundingInstruments(array($fundingInstrument));
//Add Payer to Agreement
$agreement->setPayer($payer);
// Add Shipping Address
$shippingAddress = new ShippingAddress();
$shippingAddress->setLine1('111 First Street')->setCity('Saratoga')->setState('CA')->setPostalCode('95070')->setCountryCode('US');
$agreement->setShippingAddress($shippingAddress);
// For Sample Purposes Only.
$request = clone $agreement;
// ### Create Agreement
try {
    // Please note that as the agreement has not yet activated, we wont be receiving the ID just yet.
    $agreement = $agreement->create($apiContext);
コード例 #20
0
 public function newPayment(CreditCardInterface $cardInterface, array $items, Details $shippingDetails, $paymentIntent = PaymentConst::INTENT_SALE)
 {
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher = $this->connectionService->getDispatcher();
     $dispatcher->dispatch(PaymentEvent::NEW_SETUP);
     $creditCard = new CreditCard();
     $creditCard->setType($cardInterface->getType())->setNumber($cardInterface->getNumber())->setExpireMonth($cardInterface->getExpireMonth())->setExpireYear($cardInterface->getExpireYear())->setCvv2($cardInterface->getCsc())->setFirstName($cardInterface->getFirstName())->setLastName($cardInterface->getLastName());
     $fi = new FundingInstrument();
     $fi->setCreditCard($creditCard);
     $payment = PaymentService::create($items, $shippingDetails, $paymentIntent, PaymentConst::METHOD_CREDIT_CARD, $fi);
     $paymentEvent = new PaymentEvent($payment, PaymentConst::METHOD_CREDIT_CARD);
     $dispatcher->dispatch(PaymentEvent::NEW_START, $paymentEvent);
     $result = $payment->create($apiContext);
     $paymentEvent = new PaymentEvent($result, PaymentConst::METHOD_CREDIT_CARD);
     $dispatcher->dispatch(PaymentEvent::NEW_END, $paymentEvent);
     return $result;
 }
コード例 #21
0
ファイル: PayPalApi.php プロジェクト: sebardo/ecommerce
 public function createBillingAgreement($planId, $shippingAddress, $billingAddress, $productName, $cartSummary, $cardDetails, $apiContext)
 {
     $billingPlanDefaultValues = $this->getBillingPlanDefaultValues();
     $billingAgreement = new Agreement();
     $billingAgreement->setName('Billing Agreement For ' . $productName);
     $billingAgreement->setDescription($cartSummary->paymentPlanTitle);
     $startDate = new Zend_Date();
     $startDate->addDay($billingPlanDefaultValues->startDateInterval);
     $billingAgreement->setStartDate($startDate->get(Zend_Date::ISO_8601));
     $payerInfo = new PayerInfo();
     $payerInfo->setFirstName($billingAddress->firstname);
     $payerInfo->setLastName($billingAddress->lastname);
     $payerInfo->setEmail($billingAddress->emailAddress);
     /* Fields not supported yet */
     //$payerInfo->setEmail($cart->address->billing['billing_email']);
     //$payerInfo->setPhone($cart->address->billing['billing_contactNo']);
     /* Get a MALFORMED_REQUEST error when using this field */
     //$payerInfo->setCountryCode($cart->address->billing['billing_countryCode']);
     $cardName = $cardDetails->cardName;
     $cardNumber = $cardDetails->cardNumber;
     $cardType = strtolower($cardDetails->cardType);
     $cardExpiryMonth = $cardDetails->cardExpiryMonth;
     $cardExpiryYear = $cardDetails->cardExpiryYear;
     $cardSecurityCode = $cardDetails->cardSecurityCode;
     $nameParser = new Om_Model_Name();
     $name = $nameParser->parse_name($cardName);
     $card = new CreditCard();
     $card->setType($cardType);
     $card->setNumber($cardNumber);
     $card->setExpireMonth($cardExpiryMonth);
     $card->setExpireYear($cardExpiryYear);
     $card->setCvv2($cardSecurityCode);
     $card->setFirstName($name['fname']);
     $card->setLastName($name['lname']);
     $fundingInstrument = new FundingInstrument();
     $fundingInstrument->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card");
     $payer->setFundingInstruments(array($fundingInstrument));
     $payer->setPayerInfo($payerInfo);
     $billingAgreement->setPayer($payer);
     $shippingAddressPayPal = new Address();
     $shippingAddressPayPal->setLine1($shippingAddress->addressLine1);
     $shippingAddressPayPal->setLine2($shippingAddress->addressLine2 . ' ' . $shippingAddress->addressLine3);
     $shippingAddressPayPal->setCity($shippingAddress->city);
     $shippingAddressPayPal->setCountryCode($shippingAddress->getCountry()->code);
     $shippingAddressPayPal->setPostalCode($shippingAddress->postcode);
     $shippingAddressPayPal->setState($shippingAddress->county);
     $shippingAddressPayPal->setPhone($shippingAddress->contactNumber);
     $billingAgreement->setShippingAddress($shippingAddressPayPal);
     $plan = new Plan();
     $plan->setId($planId);
     $billingAgreement->setPlan($plan);
     return $billingAgreement->create($apiContext);
 }
コード例 #22
0
 public function createCreditCard($creditCardNumber, $firstName, $lastName, $expireMonth, $expireYear, $ccv, $type = "visa")
 {
     $card = new CreditCard();
     $card->setType($type)->setNumber($creditCardNumber)->setExpireMonth($expireMonth)->setExpireYear($expireYear)->setCvv2($ccv)->setFirstName($firstName)->setLastName($lastName);
     return $card;
 }
コード例 #23
0
// API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\CreditCard;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard();
$card->setType("visa")->setNumber("4148529247832259")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->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 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 Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise
// information
コード例 #24
0
 public function actionMakepayments()
 {
     $card = new CreditCard();
     $card->setType('visa')->setNumber('4111111111111111')->setExpireMonth('06')->setExpireYear('2018')->setCvv2('782')->setFirstName('Richie')->setLastName('Richardson');
     try {
         $card->create(Yii::$app->cm->getContext());
         // ...and for debugging purposes
         echo '<pre>';
         var_dump('Success scenario');
         echo $card;
     } catch (PayPalConnectionException $e) {
         echo '<pre>';
         var_dump('Failure scenario');
         echo $e;
     }
 }
コード例 #25
0
 /**
  * Process credit card payment
  *
  * @access public
  * @param array $settings
  * @return Exception|Payment
  */
 public static function process_credit_card(array $settings)
 {
     $data = self::get_data($settings['payment_type'], $settings['object_id']);
     $card = new CreditCard();
     $card->setType(self::get_credit_card_type($settings['card_number']))->setNumber($settings['card_number'])->setExpireMonth($settings['expires_month'])->setExpireYear($settings['expires_year'])->setCvv2($settings['cvv'])->setFirstName($settings['first_name'])->setLastName($settings['last_name']);
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod('credit_card')->setFundingInstruments(array($fi));
     $item = new Item();
     $item->setName($data['title'])->setDescription($data['description'])->setCurrency($data['currency_code'])->setQuantity(1)->setPrice($data['price']);
     $item_list = new ItemList();
     $item_list->setItems(array($item));
     $details = new Details();
     $details->setSubtotal($data['price']);
     $amount = new Amount();
     $amount->setCurrency($data['currency_code'])->setTotal($data['price'])->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($item_list)->setDescription($data['description'])->setInvoiceNumber(uniqid());
     $payment = new Payment();
     $payment->setIntent('sale')->setPayer($payer)->setTransactions(array($transaction));
     try {
         $api_context = self::get_paypal_context();
         $payment->create($api_context);
         $_SESSION['alerts'][] = array('success', __('Payment has been successful.', 'realia'));
         return $payment;
     } catch (Exception $ex) {
         $_SESSION['alerts'][] = array('danger', __('There was an error processing payment.', 'realia'));
         return $ex;
     }
 }
コード例 #26
0
ファイル: PayPalPS.php プロジェクト: network-spy/pgateway
 public function pay(PaymentData $paymentData)
 {
     $paymentId = null;
     if ($paymentData->isValid()) {
         $holderName = explode(' ', $paymentData->getCCHolderName());
         $holderFirstName = '';
         $holderLastName = '';
         if (count($holderName > 1)) {
             $holderFirstName = $holderName[0];
             $holderName[0] = '';
             $holderName = trim(implode(' ', $holderName));
             $holderLastName = $holderName;
         } else {
             $holderFirstName = $paymentData->getCCHolderName();
         }
         // ### CreditCard
         // A resource representing a credit card that can be
         // used to fund a payment.
         $card = new CreditCard();
         $card->setType($paymentData->getCCType())->setNumber($paymentData->getCCNumber())->setExpireMonth($paymentData->getCCExpirationMonth())->setExpireYear($paymentData->getCCExpirationYear())->setCvv2($paymentData->getCCV2())->setFirstName($holderFirstName)->setLastName($holderLastName);
         // ### FundingInstrument
         // A resource representing a Payer's funding instrument.
         // For direct credit card payments, set the CreditCard
         // field on this object.
         $fi = new FundingInstrument();
         $fi->setCreditCard($card);
         // ### PayerInfo
         // Contains payers info data
         // commented because field email is required but user doesn't fill it in form
         /*
         $payerInfo = new PayerInfo();
         $payerInfo->setFirstName('Name')
             ->setLastName('Surname')
             ->setEmail('login@domain'); //this field is required!
         */
         // ### 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 Payer();
         $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
         //->setPayerInfo($payerInfo);
         // ### Amount
         // Lets you specify a payment amount.
         // You can also specify additional details
         // such as shipping, tax.
         $amount = new Amount();
         $amount->setCurrency($paymentData->getCurrency())->setTotal($paymentData->getAmount());
         // ### Transaction
         // A transaction defines the contract of a
         // payment - what is the payment for and who
         // is fulfilling it.
         $transaction = new Transaction();
         $transaction->setAmount($amount)->setDescription("Customer full name: " . $paymentData->getCustomerFullName())->setInvoiceNumber(uniqid());
         // ### Payment
         // A Payment Resource; create one using
         // the above types and intent set to sale 'sale'
         $payment = new Payment();
         $payment->setIntent("sale")->setPayer($payer)->setTransactions([$transaction]);
         try {
             $payment->create($this->apiContext);
             $paymentId = $payment->getId();
         } catch (\Exception $ex) {
             $this->errorMessages[] = "Error: " . $ex->getMessage() . '<br/> Details: ' . $ex->getData();
         }
     } else {
         $this->errorMessages = $paymentData->getErrorMessages();
     }
     return $paymentId;
 }
コード例 #27
0
// ### Address
// Base Address object used as shipping or billing
// address in a payment. [Optional]
$addr = new Address();
$addr->setLine1("3909 Witmer Road");
$addr->setLine2("Niagara Falls");
$addr->setCity("Niagara Falls");
$addr->setState("NY");
$addr->setPostal_code("14305");
$addr->setCountry_code("US");
$addr->setPhone("716-298-1822");
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard();
$card->setType("visa");
$card->setNumber("4417119669820331");
$card->setExpire_month("11");
$card->setExpire_year("2019");
$card->setCvv2("012");
$card->setFirst_name("Joe");
$card->setLast_name("Shopper");
$card->setBilling_address($addr);
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// Use a Payer ID (A unique identifier of the payer generated
// and provided by the facilitator. This is required when
// creating or using a tokenized funding instrument)
// and the `CreditCardDetails`
$fi = new FundingInstrument();
$fi->setCredit_card($card);
コード例 #28
0
// API used: /v1/payments/payment
require __DIR__ . '/../bootstrap.php';
use PayPal\Api\Amount;
use PayPal\Api\CreditCard;
use PayPal\Api\Details;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\Transaction;
// ### CreditCard
// A resource representing a credit card that can be
// used to fund a payment.
$card = new CreditCard();
$card->setType("visa")->setNumber("4669424246660779")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->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 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 Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise
// information
コード例 #29
0
 public function executePayment(PaymentInterface $payment, Request $request)
 {
     $order = $payment->getOrder();
     $paymentMethod = $order->getPaymentMethod();
     $configuration = $paymentMethod->getConfiguration();
     $apiContext = $this->getApiContext($configuration);
     $ccFirstname = $request->request->get('firstname');
     $ccLastname = $request->request->get('lastname');
     $ccNumber = str_replace(' ', '', $request->request->get('number'));
     $ccExpiry = $request->request->get('expiry');
     $ccCvc = $request->request->get('cvc');
     if (strlen($ccExpiry) == 0 || strlen($ccExpiry) < 5) {
         return new JsonResponse(['success' => false, 'message' => 'Upsss! Wygląda na to, że data ważności karty wpisana jest nieprawidłowo. Prosimy wprowadź ją w formacie MM/YY']);
     }
     list($ccExpiryMonth, $ccExpiryYear) = explode('/', $ccExpiry);
     if (substr($ccExpiryMonth, 0, 1) == 0) {
         $ccExpiryMonth = substr($ccExpiryMonth, 1, 1);
     }
     $ccExpiryYear = '20' . $ccExpiryYear;
     $cardType = $this->cardType($ccNumber);
     if (strlen($ccExpiryMonth) == 0 || strlen($ccExpiryYear) < 4) {
         return new JsonResponse(['success' => false, 'message' => 'Upsss! Wygląda na to, że data ważności karty wpisana jest nieprawidłowo. Prosimy wprowadź ją w formacie MM/YY']);
     }
     if ('' == $cardType) {
         return new JsonResponse(['success' => false, 'message' => 'Upsss! Wygląda na to, że wpisany numer karty jest nieprawidłowy. Prosimy wprowadź numer ponownie.']);
     }
     $card = new CreditCard();
     $card->setType($cardType);
     $card->setNumber($ccNumber);
     $card->setExpireMonth($ccExpiryMonth);
     $card->setExpireYear($ccExpiryYear);
     $card->setCvv2($ccCvc);
     $card->setFirstName($ccFirstname);
     $card->setLastName($ccLastname);
     $card->setBillingAddress($this->createAddress($order));
     $fundingInstrument = new FundingInstrument();
     $fundingInstrument->setCreditCard($card);
     $payer = $this->createPayer($configuration['paypal_type']);
     $payer->setFundingInstruments([$fundingInstrument]);
     $transaction = $this->createTransaction($order);
     $payPalPayment = new Payment();
     $payPalPayment->setIntent("sale");
     $payPalPayment->setPayer($payer);
     $payPalPayment->setTransactions([$transaction]);
     try {
         $payPalPayment->create($apiContext);
     } catch (PayPalConnectionException $e) {
         $error_object = json_decode($e->getData());
         $message = 'Upsss! Wystąpił nieoczekiwany błąd w trakcie przetwarzania transakcji. Skontaktuj się z obsługą sklepu.';
         switch ($error_object->name) {
             case 'CREDIT_CARD_CVV_CHECK_FAILED':
             case 'MISSING_CVV2':
             case 'GATEWAY_DECLINE_CVV2':
                 $message = 'Upsss! Wygląda na to, że podany przez Ciebie kod CVV2 lub CVC2 jest nieprawidłowy lub niepełny. Prosimy sprawdź numer i wprowadź go ponownie.';
                 break;
             case 'CREDIT_CARD_REFUSED':
                 $message = 'Upsss! Wygląda na to, że twój bank nie autoryzował transakcji. Prosimy spróbuj zapłacić przy użyciu innej karty.';
                 break;
             case 'EXPIRED_CREDIT_CARD':
                 $message = 'Upsss! Wygląda na to, że upłynął termin ważności twojej karty. Prosimy spróbuj zapłacić przy użyciu innej karty.';
                 break;
             case 'PAYER_EMPTY_BILLING_ADDRESS':
                 $message = 'Upsss! Wygląda na to, że podałeś niepełne dane adresowe. Prosimy sprawdź swoje dane adresowe i spróbuje ponowić płatność.';
                 break;
             case 'INVALID_CC_NUMBER':
                 $message = 'Upsss! Wygląda na to, że wpisany numer karty jest nieprawidłowy. Prosimy wprowadź numer ponownie.';
                 break;
             case 'CC_TYPE_NOT_SUPPORTED':
                 $message = 'Upsss! Nasz system nie obsługuje płatności dokonywanych tego typu kartą. Prosimy spróbuj użyć innej karty lub zmień metodę płatności na Paypal lub przelew bankowy.';
                 break;
             case 'VALIDATION_ERROR':
                 $message = 'Upsss! Podałeś niepoprawne dane karty. Spróbuj ponownie.';
                 break;
         }
         return new JsonResponse(['success' => false, 'message' => $message]);
     }
     $payment->setExternalIdentifier($payPalPayment->getId());
     if ($payment->getState() == 'approved') {
         $payment->setState(PaymentInterface::PAYMENT_STATE_APPROVED);
         return new JsonResponse(['success' => true, 'message' => 'Płatność zakończona sukcesem']);
     }
     return new JsonResponse(['success' => false, 'message' => 'Wystąpił nieoczekiwany błąd. Skontaktuj się z obsługą sklepu']);
 }
コード例 #30
-3
ファイル: PaypalController.php プロジェクト: 2ppaamm/kudotsu
 public function credit_card()
 {
     return "Hello?";
     $card = new CreditCard();
     $card->setType("visa")->setNumber("4148529247832259")->setExpireMonth("11")->setExpireYear("2019")->setCvv2("012")->setFirstName("Joe")->setLastName("Shopper");
     $fi = new FundingInstrument();
     $fi->setCreditCard($card);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     $item1 = new Item();
     $item1->setName('Ground Coffee 40 oz')->setDescription('Ground Coffee 40 oz')->setCurrency('USD')->setQuantity(1)->setTax(0.3)->setPrice(7.5);
     $item2 = new Item();
     $item2->setName('Granola bars')->setDescription('Granola Bars with Peanuts')->setCurrency('USD')->setQuantity(5)->setTax(0.2)->setPrice(2);
     $itemList = new ItemList();
     $itemList->setItems(array($item1, $item2));
     $details = new Details();
     $details->setShipping(1.2)->setTax(1.3)->setSubtotal(17.5);
     $amount = new Amount();
     $amount->setCurrency("USD")->setTotal(20)->setDetails($details);
     $transaction = new Transaction();
     $transaction->setAmount($amount)->setItemList($itemList)->setDescription("Payment description")->setInvoiceNumber(uniqid());
     $payment = new Payment();
     $payment->setIntent("sale")->setPayer($payer)->setTransactions(array($transaction));
     $request = clone $payment;
     try {
         $payment->create($apiContext);
     } catch (Exception $ex) {
         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;
 }