コード例 #1
0
 public function charge(array $data)
 {
     try {
         if ($data['onetime'] == 1) {
             $customer = Customer::Create(['source' => $data['token'], 'description' => 'name', 'email' => $data['email']]);
             $charged = Charge::create(['customer' => $customer->id, 'amount' => 1000, 'currency' => 'usd']);
             return ['customer' => $customer, 'charge' => $charged];
         }
         return Charge::create(['amount' => 1000, 'currency' => 'usd', 'description' => $data['email'], 'card' => $data['token']]);
     } catch (Card $e) {
         dd($e->getMessage());
     }
 }
コード例 #2
0
if (!isset($_REQUEST['StripeToken'])) {
    //    die();
}
global $conn;
global $config;
$emailMessage = "\nSignup for %s\n\n\nCompany: %s\n\nName: %s %s\n\n\n\nAddress\n\n%s\n\n%s, %s %s\n\n\n\nPhone: %s\n\nEmail: %s\n\n\nStripe Customer ID: %s\n\nInitial Charge ID: %s\n\n";
$query = "SELECT * FROM recurring_plan WHERE id=%s";
$query = sprintf($query, mysql_real_escape_string($_REQUEST['PlanId']));
$dbResult = mysql_query($query);
$plan = mysql_fetch_assoc($dbResult);
\Stripe\Stripe::setApiKey($config['stripeSecretKey']);
$stripeToken = $_POST['StripeToken'];
$stripeCustomerId = "";
$stripeCustomerSuccess = true;
try {
    $customer = \Stripe\Customer::Create(['source' => $stripeToken, 'plan' => $plan['stripe_plan_id'], 'email' => $_REQUEST['Email'], 'description' => $_REQUEST['CompanyName']]);
    $stripeCustomerId = $customer->id;
} catch (Exception $e) {
    $stripeCustomerId = "Error: " . $e->getMessage();
    $stripeCustomerSuccess = false;
}
if (!$stripeCustomerSuccess) {
    startPage('payment.twig', ['plan' => $plan, 'errorMessage' => $stripeCustomerId, 'postedData' => $_REQUEST]);
    exit;
}
$initialChargeNote = "";
if ($stripeCustomerSuccess && $plan['one_time_fee'] > 0) {
    $initialChargeNote = "Ran Charge for " . $plan['one_time_total'];
    try {
        \Stripe\Charge::create(['amount' => intval($plan['one_time_total'] * 100), 'currency' => 'usd', 'customer' => $customer->id]);
    } catch (Exception $e) {