create() public method

Creates a new Credit Card Resource (aka Tokenize).
public create ( ApiContext $apiContext = null, PayPalRestCall $restCall = null ) : CreditCard
$apiContext PayPal\Rest\ApiContext is the APIContext for this call. It can be used to pass dynamic configuration and credentials.
$restCall PayPal\Transport\PayPalRestCall is the Rest Call Service that is used to make rest calls
return CreditCard
 public function store(CreditCardInterface $cardInterface, Address $address = null, $externalCustomerId = null, $merchantId = null, $externalCardId = null)
 {
     $dispatcher = $this->connectionService->getDispatcher();
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher->dispatch(CreditCardEvent::STORE_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());
     if ($address instanceof Address) {
         $creditCard->setBillingAddress($address);
     }
     if ($externalCustomerId !== null) {
         $creditCard->setExternalCustomerId($externalCustomerId);
     }
     if ($merchantId !== null) {
         $creditCard->setMerchantId($merchantId);
     }
     if ($externalCardId !== null) {
         $creditCard->setExternalCardId($externalCardId);
     }
     $creditCardEvent = new CreditCardEvent($creditCard);
     $dispatcher->dispatch(CreditCardEvent::STORE_START, $creditCardEvent);
     $result = $creditCard->create($apiContext);
     $creditCardEvent = new CreditCardEvent($result);
     $dispatcher->dispatch(CreditCardEvent::STORE_END, $creditCardEvent);
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * 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();
 }
Ejemplo n.º 3
0
 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();
 }
Ejemplo n.º 4
0
// 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.
// (See bootstrap.php for more on `ApiContext`)
try {
    $card->create($apiContext);
} catch (Exception $ex) {
    // NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
    ResultPrinter::printError("Create Credit Card", "Credit Card", null, $request, $ex);
    exit(1);
}
// NOTE: PLEASE DO NOT USE RESULTPRINTER CLASS IN YOUR ORIGINAL CODE. FOR SAMPLE ONLY
ResultPrinter::printResult("Create Credit Card", "Credit Card", $card->getId(), $request, $card);
return $card;
 /**
  * @dataProvider mockProvider
  * @param CreditCard $obj
  */
 public function testCreate($obj, $mockApiContext)
 {
     $mockPPRestCall = $this->getMockBuilder('\\PayPal\\Transport\\PayPalRestCall')->disableOriginalConstructor()->getMock();
     $mockPPRestCall->expects($this->any())->method('execute')->will($this->returnValue(self::getJson()));
     $result = $obj->create($mockApiContext, $mockPPRestCall);
     $this->assertNotNull($result);
 }
 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;
     }
 }
Ejemplo n.º 7
0
$card->setCvv2("012");
$card->setFirst_name("Joe");
$card->setLast_name("Shopper");
// ### Api Context
// Pass in a `ApiContext` object to authenticate
// the call and to send a unique request id
// (that ensures idempotency). The SDK generates
// a request id if you do not pass one explicitly.
$apiContext = new ApiContext($cred, 'Request' . time());
// ### 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 the future payments.
try {
    $card->create();
} catch (\PPConnectionException $ex) {
    echo "Exception:" . $ex->getMessage() . PHP_EOL;
    var_dump($ex->getData());
    exit(1);
}
?>
<html>
<body>
	<div>Saved a new credit card with id: <?php 
echo $card->getId();
?>
</div>
	<pre><?php 
var_dump($card);
?>