· 9 years ago · Sep 16, 2016, 10:08 AM
1public function trigger_stripe(){
2
3 $stripe_keys = array(
4 "secret_key" => "sk_test_bwMnd0p3dasdaXuMv2JKQSsNRgaXf",
5 "publishable_key" => "pk_test_BHyBS8Xvm6SKadadWD7cFzVGDjlB"
6 );
7
8 $get = \Stripe\Stripe::setApiKey($stripe_keys["secret_key"]);
9
10 $create_token = \Stripe\Token::create(array(
11 "card" => array(
12 "number" => "4000000000000077",
13 "exp_month" => 7,
14 "exp_year" => 2017,
15 "cvc" => "314"
16 )
17 ));
18
19 $create_new_customer = \Stripe\Customer::create(array(
20 "description" => "Customer User Id is ".$this->session->userdata('user_id'),
21 "source" => $create_token->id ,// obtained with Stripe.js
22 "plan" => 1,
23 "email" => "raja@test.com"//$getcard_billing_email// obtained with Stripe.js
24 ));
25
26 // Retrieve the request's body and parse it as JSON
27 $input = @file_get_contents("php://input");
28 $event_json = json_decode($input);
29
30 // Verify the event by fetching it from Stripe
31 $event = \Stripe\Event::retrieve($event_json->type);
32 if($event === customer.subscription.created){
33 $data = array(
34 'value' => 'hi',
35 );
36 $this->Vendordashboard->even_trigger($data);
37
38 }else{
39
40 // do anything
41 }
42
43
44 // Do something with $event
45
46 http_response_code(200); // PHP 5.4 or greater
47
48 }