· 8 years ago · Dec 13, 2017, 02:00 PM
1function commerce_stripe_create_source($order, $secret_key, $type) {
2 if (isset($order) && isset($secret_key) && isset($type) && in_array($type, array('bancontact', 'giropay', 'ideal', 'sofort', 'alipay', 'p24'))) {
3 $wrapper = entity_metadata_wrapper('commerce_order', $order);
4 $amount = $wrapper->commerce_order_total->amount->value();
5 $billing = $wrapper->commerce_customer_billing->commerce_customer_address->value();
6 $return_url = url('checkout/' . $order->order_id . '/payment/return/' . $order->data['payment_redirect_key'], array('absolute' => TRUE));
7
8 $data = array(
9 'type' => $type,
10 'amount' => $amount,
11 'currency' => 'eur',
12 'owner' => array(
13 'email' => $order->mail,
14 'name' => empty($billing['name_line'])? $billing['first_name'] . ' ' . $billing['last_name'] : $billing['name_line'],
15 'address' => array(
16 'line1' => empty($billing['thoroughfare'])? '' : $billing['thoroughfare'],
17 'line2' => empty($billing['premise'])? '' : $billing['premise'],
18 'postal_code' => empty($billing['postal_code'])? '' : $billing['postal_code'],
19 'city' => empty($billing['locality'])? '' : $billing['locality'],
20 'country' => $billing['country']
21 )
22 ),
23 'redirect' => array(
24 'return_url' => $return_url,
25 )
26 );
27
28 // Allow modules to alter parameters of the API request.
29 drupal_alter('commerce_stripe_create_source', $data, $order);
30
31 StripeStripe::setApiKey(trim($secret_key));
32
33 return StripeSource::create($data);
34 }
35}
36
37function commmerce_stripe_sofort_commerce_stripe_create_source_alter(&$data, &$order) {
38 $data['sofort'] = array('country' => $order->data['iban_country']);
39}