PayPal\Api\CreditCard::create PHP Method

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 create($apiContext = null, $restCall = null)
    {
        $payLoad = $this->toJSON();
        $json = self::executeCall("/v1/vault/credit-cards", "POST", $payLoad, null, $apiContext, $restCall);
        $this->fromJson($json);
        return $this;
    }

Usage Example

 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;
 }
All Usage Examples Of PayPal\Api\CreditCard::create