コード例 #1
0
 /**
  * Removes a "card" from Stripe's systems.
  *
  * Sends a 'card-cancel-card' request to Stripe which remove credit card from Stripe.
  *
  * This also logs the transaction into the \Entities\RealexTransaction table,
  * and returns that object which can be queried for the request and transaction
  * state.
  *
  * If $this->_fake_transactions is true then it skips the Stripe request and returns with
  * success after performing all normal database operations as if the request was sent.
  * @see $_fake_transactions
  *
  * @param \Entities\RealexCard $card
  * @return CreditcardTrasaction $rtrans
  */
 public function cancelCard($card)
 {
     $rqTimeStamp = $this->getTimeStamp();
     $rtrans = new \Entities\RealexTransaction();
     $rtrans->setPayer($card->getPayer());
     $rtrans->setCard($card);
     $rtrans->setRequestType('card-cancel-card');
     $rtrans->setState(\Entities\RealexTransaction::STATE_INIT);
     $rtrans->setAccount($this->_account);
     $rtrans->setRequest("");
     $rtrans->setCreated(new \DateTime());
     $rtrans->setUpdated(new \DateTime());
     $rtrans->setIsFake(0);
     if ($card->getState() == \Entities\RealexCard::STATE_NONE) {
         $rtrans->setResult('00');
         $rtrans->setState(\Entities\RealexTransaction::STATE_COMPLETE);
         return $rtrans;
     }
     $this->getD2EM()->persist($rtrans);
     $this->getD2EM()->flush();
     $this->_log("[RTRANS: {$rtrans->getId()}] Stripe::cancelCard() - transaction set to STATE_INIT");
     $rtrans->getState(\Entities\RealexTransaction::STATE_PRESEND);
     $rtrans->setUpdated(new \DateTime());
     $this->getD2EM()->flush();
     $this->_log(sprintf("[RTRANS: %s] Stripe::cancelCard() - transaction set to STATE_PRESEND\n\n [ customer => '%s', card => '%s' ] \n\n", $rtrans->getId(), $card->getPayer()->getPayerref(), $card->getCardref()));
     if ($this->_fake_transactions) {
         $this->_log("[RTRANS: {$rtrans->getId()}] Stripe::cancelCard() - faking transaction");
         $card->setState(\Entities\RealexCard::STATE_NONE);
         return $this->_completeFakeTransation($rtrans);
     }
     try {
         $cu = Stripe_Customer::retrieve($card->getPayer()->getPayerref());
         $res = $cu->cards->retrieve($card->getCardref())->delete();
         $rtrans->setResult('00');
         $this->_log("[RTRANS: {$rtrans->getId()}] Stripe::cancelCard() - Stripe result: " . print_r($res, true));
     } catch (Exception $e) {
         $this->exceptionHendler($e, $rtrans, "cancelCard");
     }
     $rtrans->setState(\Entities\RealexTransaction::STATE_COMPLETE);
     $rtrans->setUpdated(new \DateTime());
     $this->getD2EM()->flush();
     if ($rtrans->isSuccessful()) {
         $card->setState(\Entities\RealexCard::STATE_NONE);
         $card->setUpdated();
         $this->getD2EM()->flush();
     }
     return $rtrans;
 }
コード例 #2
0
 /**
  * Removes a "card" from Realex's systems.
  *
  * Sends a 'card-cancel-card' request to Realex which remove credit card from Realex.
  *
  * This also logs the transaction into the \Entities\RealexTransaction table,
  * and returns that object which can be queried for the request and transaction
  * state.
  *
  * If $this->_fake_transactions is true then it skips the Realex request and returns with
  * success after performing all normal database operations as if the request was sent.
  * @see $_fake_transactions
  *
  * @param \Entities\RealexCard $card
  * @return CreditcardTrasaction $rtrans
  */
 public function cancelCard($card)
 {
     $rqTimeStamp = $this->getTimeStamp();
     $rtrans = new \Entities\RealexTransaction();
     $rtrans->setPayer($card->getPayer());
     $rtrans->setCard($card);
     $rtrans->setRequestType('card-cancel-card');
     $rtrans->setState(\Entities\RealexTransaction::STATE_INIT);
     $rtrans->setAccount($this->_account);
     $rtrans->setRequest("");
     $rtrans->setCreated(new \DateTime());
     $rtrans->setUpdated(new \DateTime());
     $rtrans->setIsFake(0);
     if ($card->getState() == \Entities\RealexCard::STATE_NONE) {
         $rtrans->setResult('00');
         $rtrans->setState(\Entities\RealexTransaction::STATE_COMPLETE);
         return $rtrans;
     }
     $this->getD2EM()->persist($rtrans);
     $this->getD2EM()->flush();
     $this->_log("[RTRANS: {$rtrans->getId()}] Realex::cancelCard() - transaction set to STATE_INIT");
     $cardRef = $card->getCardref();
     $payerRef = $card->getPayer()->getPayerref();
     $rqHash = OSS_PaymentProcessor_Realex_Hash::removeCreditCard($rqTimeStamp, $this->getMerchantId(), $payerRef, $cardRef, $this->getMerchantSecret());
     $reqXML = "<request type='card-cancel-card' timestamp='{$rqTimeStamp}'>\n                       <merchantid>{$this->getMerchantId()}</merchantid>\n                           <card>\n                           <ref>{$cardRef}</ref>\n                           <payerref>{$payerRef}</payerref>\n                           <chname>{$card->getHolder()}</chname>\n                       </card>\n                       <sha1hash>{$rqHash}</sha1hash>\n                   </request>";
     $rtrans->getState(\Entities\RealexTransaction::STATE_PRESEND);
     $rtrans->setUpdated(new \DateTime());
     $this->getD2EM()->flush();
     $this->_log("[RTRANS: {$rtrans->getId()}] Realex::cancelCard() - transaction set to STATE_PRESEND\n\n{$reqXML}\n\n");
     if ($this->_fake_transactions) {
         $this->_log("[RTRANS: {$rtrans->getId()}] Realex::cancelCard() - faking transaction");
         $card->setState(\Entities\RealexCard::STATE_NONE);
         return $this->_completeFakeTransation($rtrans);
     }
     $this->_sendRequest($rtrans, $reqXML);
     if ($rtrans->isSuccessful()) {
         $card->setState(\Entities\RealexCard::STATE_NONE);
         $this->getD2EM()->flush();
     }
     return $rtrans;
 }