コード例 #1
0
 /**
  * Submit a payment through the PaymentWall Library.
  *
  * @param mixed $data
  *
  * @return Response
  */
 public function sendData($data)
 {
     // Initialise the PaymentWall configuration
     $this->setPaymentWallObject();
     // if no token exists, create one
     if (empty($data['purchase']['token'])) {
         // Create a one time token
         $tokenModel = new \Paymentwall_OneTimeToken();
         $tokenObject = $tokenModel->create($data['card']);
         if ($tokenObject->type == 'Error') {
             return $this->returnError($tokenObject->error, $tokenObject->code);
         }
         $data['purchase']['token'] = $tokenObject->getToken();
     }
     if (empty($data['purchase']['token'])) {
         return $this->returnError('Payment Token could not be created', 231);
     }
     // Now we know that we have an actual token (one time or
     // permanent), we can create the charge request.
     $charge = new \Paymentwall_Charge();
     try {
         $charge->create($data['purchase']);
     } catch (\Exception $e) {
         return $this->returnError('Cannot process payment', 231, $charge->getResponseLogInformation());
     }
     // Force the charge properties to be an array
     $properties = $charge->getProperties();
     $properties = json_decode(json_encode($properties), true);
     // Construct the response object
     $this->response = new Response($this, $properties);
     if ($charge->isSuccessful()) {
         if ($charge->isCaptured()) {
             $this->response->setCaptured(true);
         } elseif ($charge->isUnderReview()) {
             $this->response->setUnderReview(true);
         }
     }
     return $this->response;
 }