· 9 years ago · Dec 30, 2016, 03:04 PM
1public function createtransaction($customer_id, $paymentDesc, $destinationAccount) {
2
3 $errors = array();
4 try {
5 $secret_key = $this->get_secret_key();
6
7 StripeStripe::setApiKey($secret_key);
8
9 // THIS ONLY FOR TESTING PURPOSE. WE WANT SEE IF CAN ACCESS TO CONNECTED ACCOUNT
10 // Fetching an account just needs the ID as a parameter
11 // WHIT ACCESS_TOKEN WORKS THE RETRIEVE METHOD
12 // $account = StripeAccount::retrieve('access_token_from_db');
13 // WHIT ACCOUNT_ID DOES NOT. RETURNS AN ERROR
14 // $account = StripeAccount::retrieve('acct_***********');
15 // echo "<pre>------";
16 // print_r($account);
17 // echo "-----</pre>";
18
19
20 // HERE ONLY WE CAN TEST IF WE CAN CREATE A CUSTOMER. THIS IS ONLY TO CHECK IF THE ACCOUNT IS CONNECTED. THE CUSTOMER ALREADY EXISTS IN MAIN ACCOUNT
21 // Recommended: sending API key with every request
22 // StripeCustomer::create(
23 // array("description" => "example@stripe.com"),
24 // array("api_key" => 'sk_test_***************') // account's access token from the Connect flow
25 // SAME. WITH stripe_account DOES NOT WORK. WHIT api_key PARAM WORKS WELL
26 // );
27
28 // THE DOCS SAYS WE NEED CREATE A TOEKN WITH customer AND stripe_account, BUT IT RETURNS AN ERROR OF PERMISSION
29 // Create a Token from the existing customer on the platform's account
30 // $token = StripeToken::create(
31 // array("customer" => $customer_id),
32 // array("stripe_account" => 'acct_********************') // id of the connected account
33 // );
34
35 // echo "<pre>------";
36 // print_r($token);
37 // echo "-----</pre>";
38
39 // ONE COMBINATION. DOES NOT WORK
40 // var_dump($customer_id, $paymentDesc, $destinationAccount);
41 // $charge = StripeCharge::create(array(
42 // "amount" => $paymentDesc['total'] * 100,
43 // "currency" => "usd",
44 // "source" => $token,
45 // "description" => $paymentDesc['description'],
46 // 'destination' => $destinationAccount
47 // ));
48 //
49 //
50
51 // IT WORKS IN THE MAIN ACCOUNT BUT IT IS NOT OUR GOAL, BUT WE CAN TRANSFER THE MONEY TO ANOTHER CONNECTED ACCOUNT
52 // $charge = StripeCharge::create(array(
53 // 'amount' => $paymentDesc['total'] * 100,
54 // 'currency' => 'usd',
55 // 'customer' => $customer_id,
56 // "description" => $paymentDesc['description']
57 // ));
58
59 // ANOTHER COMBINATION. DOES NOT WORK
60 /*$charge = StripeCharge::create(array(
61 'amount' => $paymentDesc['total'] * 100,
62 'currency' => 'usd',
63 "description" => $paymentDesc['description'],
64 'customer' => $customer_id
65 ), array('stripe_account' => 'acct_************'));*/
66
67 // ANOTHER COMBINATION. DOES NOT WORK
68 /*$charge = StripeCharge::create(array(
69 'amount' => $paymentDesc['total'] * 100,
70 'currency' => 'usd',
71 "description" => $paymentDesc['description'],
72 'customer' => $customer_id
73 ), array('api_key' => 'ACCESS_TOKEN_IN_DB'));
74
75 echo "<pre>------";
76 print_r($charge);
77 echo "-----</pre>";
78
79 return array('charge' => $charge);*/
80
81 } catch(Stripe_CardError $e) {
82 $errors = array('error' => false, 'message' => 'Card was declined.', 'e' => $e);
83 } catch (Stripe_InvalidRequestError $e) {
84 $errors = array('error' => false, 'message' => 'Invalid parameters were supplied to Stripe's API', 'e' => $e);
85 } catch (Stripe_AuthenticationError $e) {
86 $errors = array('error' => false, 'message' => 'Authentication with Stripe's API failed!', 'e' => $e);
87 } catch (Stripe_ApiConnectionError $e) {
88 $errors = array('error' => false, 'message' => 'Network communication with Stripe failed', 'e' => $e);
89 } catch (Stripe_Error $e) {
90 $errors = array('error' => false, 'message' => 'Stripe error. Something wrong just happened!', 'e' => $e);
91 } catch (Exception $e) {
92 $errors = array('error' => false, 'message' => 'An error has ocurred getting info customer.', 'e' => $e);
93 }
94
95 return $errors;
96 }