public function create()
 {
     // get input
     $input = array('user_id' => Auth::user()->id, 'type_name' => Input::get('type_name'), 'type_id' => Input::get('type_id'), 'currency' => Input::get('currency'), 'total' => Input::get('total'), 'message' => Input::get('message'), 'as_noname' => Input::get('as_noname'));
     $result = Donation::add($input);
     if ($result['success']) {
         // if success
         // create donation code
         $donation_code = Donation::generateDonationCode($result['data']->id);
         if (Request::ajax()) {
             return Response::json(['success' => true, 'redirect_url' => URL::route('lihat-donasi', $donation_code)]);
         } else {
             return $result;
         }
     } else {
         // if fail
         if (Request::ajax()) {
             return Response::json(json_encode($result));
         } else {
             return $result;
         }
     }
     return $result;
 }
Esempio n. 2
0
require '../includes/classes/API.php';
header("Access-Control-Allow-Origin: *");
$sql->options['error_handling'] = 'die';
$api = new API();
$api->post('/donation/add', function () {
    global $QUERY;
    if (isset($QUERY['created_at']) and $QUERY['created_at']) {
        $QUERY['created_at'] = date("Y-m-d", strtotime($QUERY['created_at']));
    } else {
        $QUERY['created_at'] = date('Y-m-d H:i:s');
    }
    if (isset($QUERY['donation_type']) and $QUERY['donation_type'] == 'gg') {
        $QUERY['donation_type'] = 'globalgiving';
    }
    $donations = new Donation();
    $donation_id = $donations->add($QUERY);
    if ($donation_id) {
        showSuccess("Donation inserted succesfully : Donation ID '.{$donation_id}.'", array("donation" => array("id" => $donation_id)));
    } else {
        showError("Failure in insterting dontaion at server. Try again after some time.");
    }
});
$api->get('/donation/get_donations_for_approval/{poc_id}', function ($poc_id) {
    $donation = new Donation();
    $donations_for_approval = $donation->getDonationsForApproval($poc_id);
    if ($donations_for_approval) {
        showSuccess(count($donations_for_approval) . " donation(s) waiting for approval", array('donations' => $donations_for_approval));
    } else {
        $error = $donation->error;
        if (!$error) {
            $error = "Can't find any donations that need approval for this user";
Esempio n. 3
0
 public function create()
 {
     // get input
     $input = Input::all();
     if (Auth::check()) {
         $input['user_id'] = Auth::user()->id;
     } else {
         // Check apakah user ada di database
         $check_user = User::where('email', $input['email']);
         if ($check_user->count() > 0) {
             $input['user_id'] = $check_user->pluck('id');
         } else {
             // Membuat user baru dengan status draft (status:2)
             $post = new User();
             $post->email = $input['email'];
             $post->status = 2;
             $post->save();
             $input['user_id'] = $post->id;
         }
     }
     unset($input['email']);
     $result = Donation::add($input);
     if ($result['success']) {
         // if success
         // create donation code
         $donation_code = Donation::generateDonationCode($result['data']->id);
         if (Request::ajax()) {
             return Response::json(['success' => true, 'redirect_url' => URL::route('lihat-donasi', $donation_code)]);
         } else {
             return $result;
         }
     } else {
         // if fail
         if (Request::ajax()) {
             return Response::json(json_encode($result));
         } else {
             return $result;
         }
     }
     return $result;
 }