execute(); //increment the rate limiter on every submit. this form should be pretty low traffic for most $req = "number,name,expiry,cvc,amount"; $required = check_required(explode(',',$req), $frm); $amount = explode('.', $frm['amount']); if(count($amount) == 1){ $amt = $amount[0] * 100; }elseif(count($amount) == 2){ $amt = $amount[0] . $amount[1]; } if($required){ $data['error'] = TRUE; $data['message'] = $required['msg']; $data['error_fields'] = $required['field']; }elseif($amt < 50 || $amt > 100000){ $data['error'] = TRUE; $data['message'] = "Invalid amount. Amount must be between $0.50 and $1,000.00"; $data['error_fields'] = array("amount" => 1); }else{ try{ $dates = explode('/', $frm['expiry']); $expiry_month = (int) $dates[0]; $expiry_year = (int) $dates[1]; $amount = explode('.', $frm['amount']); if(count($amount) == 1){ $amt = $amount[0] * 100; }elseif(count($amount) == 2){ $amt = $amount[0] . $amount[1]; } \Stripe\Stripe::setApiKey($CFG->api_key['stripe']); $myCard = array('number' => $frm['number'], 'exp_month' => $expiry_month, 'exp_year' => $expiry_year, 'cvc' => $frm['cvc'], 'name' => $frm['name']); $charge = \Stripe\Charge::create(array('card' => $myCard, 'amount' => intval($amt), 'currency' => 'usd', 'description' => $frm['invoice'])); $data['paid'] = TRUE; } catch(\Stripe\Error\Card $e) { // Since it's a decline, \Stripe\Error\Card will be caught $body = $e->getJsonBody(); $err = $body['error']; $data['error'] = TRUE; $data['message'] = $err['message']; /* print('Status is:' . $e->getHttpStatus() . "\n"); print('Type is:' . $err['type'] . "\n"); print('Code is:' . $err['code'] . "\n"); // param is '' in this case print('Param is:' . $err['param'] . "\n"); print('Message is:' . $err['message'] . "\n"); */ //print_r($err); } catch (\Stripe\Error\InvalidRequest $e) { // Invalid parameters were supplied to Stripe's API } catch (\Stripe\Error\Authentication $e) { // Authentication with Stripe's API failed // (maybe you changed API keys recently) } catch (\Stripe\Error\ApiConnection $e) { // Network communication with Stripe failed } catch (\Stripe\Error\Base $e) { // Display a very generic error to the user, and maybe send // yourself an email } catch (Exception $e) { // Something else happened, completely unrelated to Stripe } } } require_once("{$CFG->includedir}/header.inc"); require_once("{$CFG->includedir}/payment.inc"); require_once("{$CFG->includedir}/footer.inc"); ?>