コード例 #1
0
 /**
  * @api {post} /ecommerce/purchase Make Purchase
  * @apiName Make Purchase
  * @apiGroup Transaction
  * @apiHeader (Header) {String} X_Authorization Authorization value.
  * @apiParam  {String[]} items cart items in json format
  * @apiParam  {Number} amount Total amount.
  * @apiParam  {Number} card_num Credit Cart Number.
  * @apiParam  {String} exp_date Credit Cart exp date in 'm/y' format.
  *
  * @apiParam  (items) {Number} id course_sale_id
  * @apiParam  (items) {Number} course_id Course Id.
  * @apiParam  (items) {String} name Course Name.
  * @apiParam  (items) {Number} price final price.
  * @apiParam  (items) {Number} qty qty.
  * 
  * @apiError 400 Input Invalid. This will happen if the param is missing or not the valid format.
  * @apiError 404 Not found. This will happen if the role id/user id/group id is not in our system.
  * @apiError 401 Not authorized. This will happen if the header value is not attached.
  * 
  * 
  */
 public static function purchase()
 {
     $app = \Slim\Slim::getInstance();
     $data = $app->request->post();
     $idUser = self::authCheck();
     self::inputValid();
     self::cartCheck();
     $data['cust_id'] = $idUser;
     $transaction = new Authorize();
     $transaction->setCustomer($data);
     $transaction->addItem(json_decode($data['items']));
     $result = $transaction->AIM($data['amount'], $data['card_num'], $data['exp_date']);
     if (!$result->approved) {
         $app->halt(400, json_encode($result->response_reason_text));
     }
     EnrollmentController::afterPurchaseEnroll(json_decode($data['items']), $idUser);
     return json_encode($result);
 }