예제 #1
1
 public function refundSale($saleId, $refundAmount, $currency = CurrencyConst::EURO)
 {
     $apiContext = $this->connectionService->getApiContext();
     $amount = new Amount();
     $amount->setCurrency($currency)->setTotal($refundAmount);
     $refund = new Refund();
     $refund->setAmount($amount);
     $sale = new Sale();
     $sale->setId($saleId);
     $refundSale = $sale->refund($refund, $apiContext);
     return $refundSale;
 }
 /**
  * @param array $items
  * @param $shippingDetails
  * @param string $intent
  * @throws Exception
  * @return null|string
  */
 public function createPayment(array $items, Details $shippingDetails, $intent = PaymentConst::INTENT_SALE)
 {
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher = $this->connectionService->getDispatcher();
     $dispatcher->dispatch(PaymentEvent::NEW_SETUP);
     $successUrl = '';
     $cancelUrl = '';
     switch ($intent) {
         case PaymentConst::INTENT_SALE:
             $successUrl = $this->router->generate('paypal_payment_sale_success', array(), true);
             $cancelUrl = $this->router->generate('paypal_payment_sale_cancel', array(), true);
             break;
         case PaymentConst::INTENT_AUTHORIZE:
             $successUrl = $this->router->generate('paypal_payment_authorize_success', array(), true);
             $cancelUrl = $this->router->generate('paypal_payment_authorize_cancel', array(), true);
             break;
     }
     $redirectUrls = new RedirectUrls();
     $redirectUrls->setReturnUrl($successUrl)->setCancelUrl($cancelUrl);
     $payment = PaymentService::create($items, $shippingDetails, $intent, PaymentConst::METHOD_PAYPAL);
     $payment->setRedirectUrls($redirectUrls);
     $paymentEvent = new PayPalPaymentEvent($payment);
     $dispatcher->dispatch(PaymentEvent::NEW_START, $paymentEvent);
     $result = $payment->create($apiContext);
     $paymentEvent = new PayPalPaymentEvent($result);
     $dispatcher->dispatch(PaymentEvent::NEW_END, $paymentEvent);
     $payment->create($apiContext);
     $approvalUrl = $payment->getApprovalLink();
     return $approvalUrl;
 }
 public function update($creditCardToken, array $updateInfo)
 {
     $apiContext = $this->connectionService->getApiContext();
     $dispatcher = $this->connectionService->getDispatcher();
     $creditCard = $this->getDetails($creditCardToken);
     $creditCardEvent = new CreditCardEvent($creditCard);
     $dispatcher->dispatch(CreditCardEvent::UPDATE_START, $creditCardEvent);
     $patchRequest = new PatchRequest();
     foreach ($updateInfo as $operation => $fields) {
         $allowedOperation = Validation::updateOP($operation);
         if ($allowedOperation) {
             $patch = new Patch();
             $patch->setOp($operation);
             foreach ($fields as $key => $value) {
                 $patch->setPath($key)->setValue($value);
             }
             $patchRequest->addPatch(clone $patch);
         }
     }
     $result = $creditCard->update($patchRequest, $apiContext);
     $creditCardEvent = new CreditCardEvent($result);
     $dispatcher->dispatch(CreditCardEvent::UPDATE_END, $creditCardEvent);
     return true;
 }