A resource representing a credit card that can be used to fund a payment.
Inheritance: extends PayPal\Common\PayPalModel
Exemplo n.º 1
0
 public function testSerializeDeserialize()
 {
     $t1 = $this->ccToken;
     $t2 = new CreditCardToken();
     $t2->fromJson($t1->toJson());
     $this->assertEquals($t1, $t2);
 }
Exemplo n.º 2
0
 /**
  * Create a payment using a previously obtained
  * credit card id. The corresponding credit
  * card is used as the funding instrument.
  * 
  * @param string $creditCardId credit card id
  * @param string $total Payment amount with 2 decimal points
  * @param string $currency 3 letter ISO code for currency
  * @param string $paymentDesc
  */
 function makePaymentUsingCC($creditCardId, $total, $currency, $paymentDesc)
 {
     $ccToken = new CreditCardToken();
     $ccToken->setCreditCardId($creditCardId);
     $fi = new FundingInstrument();
     $fi->setCreditCardToken($ccToken);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card");
     $payer->setFundingInstruments(array($fi));
     // Specify the payment amount.
     $amount = new Amount();
     $amount->setCurrency($currency);
     $amount->setTotal($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 Transaction();
     $transaction->setAmount($amount);
     $transaction->setDescription($paymentDesc);
     $payment = new Payment();
     $payment->setIntent("sale");
     $payment->setPayer($payer);
     $payment->setTransactions(array($transaction));
     $payment->create(new Paypalinit());
     return $payment;
 }
Exemplo n.º 3
0
 public function createPayer($creditCardId, $userId)
 {
     $ccToken = new CreditCardToken();
     $ccToken->setCreditCardId($creditCardId)->setPayerId($userId);
     $fi = new FundingInstrument();
     $fi->setCreditCardToken($ccToken);
     //$payerInfo = new PayerInfo();
     //$payerInfo->setPayerId($userId);
     $payer = new Payer();
     $payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
     return $payer;
 }
 /**
  * @depends testSerializationDeserialization
  * @param CreditCardToken $obj
  */
 public function testGetters($obj)
 {
     $this->assertEquals($obj->getCreditCardId(), "TestSample");
     $this->assertEquals($obj->getPayerId(), "TestSample");
     $this->assertEquals($obj->getLast4(), "TestSample");
     $this->assertEquals($obj->getType(), "TestSample");
     $this->assertEquals($obj->getExpireMonth(), 123);
     $this->assertEquals($obj->getExpireYear(), 123);
 }
/** @var CreditCard $card */
$card = (require __DIR__ . '/../vault/CreateCreditCard.php');
use PayPal\Api\Amount;
use PayPal\Api\Details;
use PayPal\Api\Item;
use PayPal\Api\ItemList;
use PayPal\Api\CreditCardToken;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
use PayPal\Api\CreditCard;
// ### Credit card token
// Saved credit card id from a previous call to
// CreateCreditCard.php
$creditCardToken = new CreditCardToken();
$creditCardToken->setCreditCardId($card->getId());
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// For stored credit card payments, set the CreditCardToken
// field on this object.
$fi = new FundingInstrument();
$fi->setCreditCardToken($creditCardToken);
// ### Payer
// A resource representing a Payer that funds a payment
// For stored credit card payments, set payment method
// to 'credit_card'.
$payer = new Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise
Exemplo n.º 6
0
 public function doSaleAPI($creditCardId, $total)
 {
     $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);
     $creditCardToken = new CreditCardToken();
     $creditCardToken->setCreditCardId($creditCardId);
     $fundingInstrument = new FundingInstrument();
     $fundingInstrument->setCreditCardToken($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 $payment->getId();
 }
 public function newPaymentFromStored($creditCardToken, array $items, Details $shippingDetails, $paymentIntent = PaymentConst::INTENT_SALE)
 {
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher = $this->connectionService->getDispatcher();
     $dispatcher->dispatch(PaymentEvent::NEW_SETUP);
     $creditCard = $this->getDetails($creditCardToken);
     $creditCardToken = new CreditCardToken();
     $creditCardToken->setCreditCardId($creditCard->getId());
     $fi = new FundingInstrument();
     $fi->setCreditCardToken($creditCardToken);
     $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;
 }
use PayPal\Api\Address;
use PayPal\Api\Amount;
use PayPal\Api\CreditCard;
use PayPal\Api\CreditCardToken;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\RedirectUrls;
use PayPal\Api\Transaction;
use PayPal\Auth\OAuthTokenCredential;
use PayPal\Rest\ApiContext;
// ### Credit card token
// Saved credit card id from a previous call to
// CreateCreditCard.php
$creditCardId = 'CARD-5BT058015C739554AKE2GCEI';
$creditCardToken = new CreditCardToken();
$creditCardToken->setCredit_card_id($creditCardId);
// ### 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_token($creditCardToken);
// ### Payer
// A resource representing a Payer that funds a payment
// Use the List of `FundingInstrument` and the Payment Method
// as 'credit_card'
$payer = new Payer();
$payer->setPayment_method("credit_card");
// Payment using a previously stored credit card token.
// 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\CreditCardToken;
use PayPal\Api\Payer;
use PayPal\Api\Payment;
use PayPal\Api\FundingInstrument;
use PayPal\Api\Transaction;
// ### Credit card token
// Saved credit card id from a previous call to
// CreateCreditCard.php
$creditCardToken = new CreditCardToken();
$creditCardToken->setCreditCardId('CARD-29H07236G1554552FKINPBHQ');
// ### FundingInstrument
// A resource representing a Payer's funding instrument.
// For stored credit card payments, set the CreditCardToken
// field on this object.
$fi = new FundingInstrument();
$fi->setCreditCardToken($creditCardToken);
// ### Payer
// A resource representing a Payer that funds a payment
// For stored credit card payments, set payment method
// to 'credit_card'.
$payer = new Payer();
$payer->setPaymentMethod("credit_card")->setFundingInstruments(array($fi));
// ### Itemized information
// (Optional) Lets you specify item wise