- if ($type == 'google') {
- // return if response smell invalid
- if (!array_key_exists('risk-information-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
- return FALSE;
- }
- $riskInfo = &$apiParams[1][$apiParams[0]]['notifications']['risk-information-notification'];
-
- if (array_key_exists('new-order-notification', $apiParams[1][$apiParams[0]]['notifications'])) {
- $newOrder = &$apiParams[1][$apiParams[0]]['notifications']['new-order-notification'];
- }
-
- if ($riskInfo['google-order-number']['VALUE'] == $apiParams[2]['google-order-number']['VALUE']) {
- foreach ($riskInfo['risk-information']['billing-address'] as $field => $info) {
- if (!empty($mapper['location'][$field])) {
- $params['address'][1][$mapper['location'][$field]] = $info['VALUE'];
- }
- elseif (!empty($mapper['contact'][$field])) {
- if ($newOrder && !empty($newOrder['buyer-billing-address']['structured-name'])) {
- foreach ($newOrder['buyer-billing-address']['structured-name'] as $namePart => $nameValue) {
- $params[$mapper['contact'][$namePart]] = $nameValue['VALUE'];
- }
- }
- else {
- $params[$mapper['contact'][$field]] = $info['VALUE'];
- }
- }
- elseif (!empty($mapper['transaction'][$field])) {
- $transaction[$mapper['transaction'][$field]] = $info['VALUE'];
- }
- }
-
- // Response is an huge array. Lets pickup only those which we ineterested in
- // using a local mapper, rather than traversing the entire array.
- $localMapper = array(
- 'google-order-number' => $riskInfo['google-order-number']['VALUE'],
- 'total-charge-amount' => $apiParams[2]['total-charge-amount']['VALUE'],
- 'currency' => $apiParams[2]['total-charge-amount']['currency'],
- 'item-name' => $newOrder['shopping-cart']['items']['item']['item-name']['VALUE'],
- 'timestamp' => $apiParams[2]['timestamp']['VALUE'],
- );
- if (array_key_exists('latest-charge-fee', $apiParams[2])) {
- $localMapper['latest-charge-fee'] = $apiParams[2]['latest-charge-fee']['total']['VALUE'];
- $localMapper['net-amount'] = $localMapper['total-charge-amount'] - $localMapper['latest-charge-fee'];
- }
-
- // This is a subscription (recurring) donation.
- if (array_key_exists('subscription', $newOrder['shopping-cart']['items']['item'])) {
- $subscription = $newOrder['shopping-cart']['items']['item']['subscription'];
- $localMapper['amount'] = $newOrder['order-total']['VALUE'];
- $localMapper['times'] = $subscription['payments']['subscription-payment']['times'];
- // Convert Google's period to one compatible with the CiviCRM db field.
- $freqUnits = array(
- 'DAILY' => 'day',
- 'WEEKLY' => 'week',
- 'MONHTLY' => 'month',
- 'YEARLY' => 'year',
- );
- $localMapper['period'] = $freqUnits[$subscription['period']];
- // Unlike PayPal, Google has no concept of freq. interval, it is always 1.
- $localMapper['frequency_interval'] = '1';
- // Google Checkout dates are in ISO-8601 format. We need a format that
- // MySQL likes
- $unix_timestamp = strtotime($localMapper['timestamp']);
- $mysql_date = date('YmdHis', $unix_timestamp);
- $localMapper['modified_date'] = $mysql_date;
- $localMapper['start_date'] = $mysql_date;
- // This is PayPal's nomenclature, but just use it for Google as well since
- // we act on the value of trxn_type in processAPIContribution().
- $localMapper['trxn_type'] = 'subscrpayment';
- }
-
- foreach ($localMapper as $localKey => $localVal) {
- if (!empty($mapper['transaction'][$localKey])) {
- $transaction[$mapper['transaction'][$localKey]] = $localVal;
- }
- }
-
- if (empty($params) && empty($transaction)) {
- continue;
- }
-
- if (!empty($transaction) && $category) {
- $params['transaction'] = $transaction;
- }
- else {
- $params += $transaction;
- }
-
- CRM_Contribute_BAO_Contribution_Utils::_fillCommonParams($params, $type);
- }
- return $params;
- }