setBillingAddress() public method

Billing Address associated with this card.
public setBillingAddress ( Address $billing_address )
$billing_address Address
 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;
 }
示例#2
0
 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);
 }
示例#3
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->setPostalCode("14305");
     $addr->setCountryCode("US");
     $addr->setPhone("716-298-1822");
     $card = new CreditCard();
     $card->setType("visa");
     $card->setNumber("4417119669820331");
     $card->setExpireMonth("11");
     $card->setExpireYear("2019");
     $card->setCvv2("012");
     $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));
     $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'];
 }
 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
 }
 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']);
 }
示例#6
0
 public function setPaypalCard($number, $type, $expireMonth, $expireYear, $cvv2, $firstname, $lastname, $addr)
 {
     $card = new CreditCard();
     $card->setNumber($number);
     $card->setType($type);
     $card->setExpireMonth($expireMonth);
     $card->setExpireYear($expireYear);
     $card->setCvv2($cvv2);
     $card->setFirstName($firstname);
     $card->setLastName($lastname);
     $card->setBillingAddress($addr);
     return $card;
 }