add in checkout success and failure functions; rework to fit with amends to direct pay flow

master
Marek Isalski 9 years ago
parent fc68408a63
commit 285672453a

@ -49,6 +49,18 @@ function fulcrm_shoppingcart_menu() {
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
$items[ 'fulcrm/checkout/success/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout_success',
'page arguments' => array(3,4),
'type' => MENU_CALLBACK,
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
$items[ 'fulcrm/checkout/failure/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout_failure',
'page arguments' => array(3,4),
'type' => MENU_CALLBACK,
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
return $items;
}
@ -196,7 +208,7 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
$api_data = fulcrm_apiv2_POST( 'shoppingitem/', $item, $query = array( 'expand' => 'd' ) );
if ( $api_data[ 'success' ] ) {
drupal_set_message( t('Added to shopping cart.'), 'status' );
drupal_set_message( t('Added "%item" to shopping cart.', array( '%item' => $item[ 'd' ][ 'name' ] ) ), 'status' );
$form_state[ 'redirect' ] = 'fulcrm/cart';
} else {
drupal_set_message( t('There was a problem adding your item to the shopping cart.'), 'error' );
@ -390,17 +402,39 @@ function fulcrm_shoppingcart_cart() {
function fulcrm_shoppingcart_checkout() {
$cart = fulcrm_shoppingcart_get_session_cart( false );
if ( $cart && array_key_exists( 'url', $cart ) ) {
$transaction_data = fulcrm_apiv2_POST( $cart[ 'url' ] . 'transaction/', array(), $query = array( 'expand' => implode( ',', array( 'd',
'lineitems',
'lineitems.d',
'lineitems.content_object',
// XXX 'lineitems.content_object.d',
'paymentitems',
'paymentitems.d',
) ) ) );
if ( $transaction_data[ 'success' ] )
return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data[ 'data' ] ) );
$transaction_data = fulcrm_apiv2_POST( $cart[ 'url' ] . 'transaction/', array(), array( 'expand' => implode( ',', array( 'd' ) ) ) );
if ( $transaction_data[ 'success' ] ) {
$hmac = fulcrm_crypto_object_id_hmac( 'transaction', $transaction_data[ 'data' ][ 'id' ] );
$transaction_push = array( 'd' => array( 'fulcrm_fund_transaction_pay_failure_url' => url( 'fulcrm/checkout/failure/' . $transaction_data[ 'data' ][ 'id' ]. '/' . $hmac, array( 'absolute' => TRUE ) ),
'fulcrm_fund_transaction_complete_success_url' => url( 'fulcrm/checkout/success/' . $transaction_data[ 'data' ][ 'id' ]. '/' . $hmac, array( 'absolute' => TRUE ) ),
'fulcrm_fund_transaction_complete_failure_url' => url( 'fulcrm/checkout/failure/' . $transaction_data[ 'data' ][ 'id' ]. '/' . $hmac, array( 'absolute' => TRUE ) ),
),
);
$transaction_data2 = fulcrm_apiv2_PATCH( $transaction_data[ 'data' ][ 'url' ],
$transaction_push, $query = array( 'expand' => implode( ',', array( 'd',
'lineitems',
'lineitems.d',
'lineitems.content_object',
// XXX 'lineitems.content_object.d',
'paymentitems',
'paymentitems.d',
) ) ) );
if ( $transaction_data2[ 'success' ] ) {
return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data2[ 'data' ] ) );
}
return 'problem 3';
}
return 'problem 2';
}
return 'problem 1';
}
function fulcrm_shoppingcart_checkout_success( $transaction_id, $hmac ) {
return 'success';
}
function fulcrm_shoppingcart_checkout_failure( $transaction_id, $hmac ) {
return 'failure';
}

@ -27,7 +27,7 @@
<tr>
<td><a class="btn btn-success" href="<?php check_plain( variable_get( 'fulcrm_shoppingcart_proceed_url', url('<front>') ) )?>"><?php print check_plain( variable_get( 'fulcrm_shoppingcart_proceed_text', '' ) ); ?></a></td>
<td colspan="2">&nbsp;</td>
<td class="text-right"><?php foreach ( ( $transaction[ '_paymentmethods' ][ 'preferred' ] + $transaction[ '_paymentmethods' ][ 'other' ] ) as $paymentmethod ): ?><a class="btn btn-primary" href="<?php print $paymentmethod[ 'payment_url' ]; ?>"><?php print check_plain( $paymentmethod[ 'name' ] ); ?></a><?php endforeach; ?></td>
<td class="text-right"><?php foreach ( ( $transaction[ '_paymentmethods' ][ 'pay' ][ 'preferred' ] + $transaction[ '_paymentmethods' ][ 'pay' ][ 'other' ] ) as $paymentmethod ): ?><a class="btn btn-primary" href="<?php print $paymentmethod[ 'payment_direct_url' ]; ?>"><?php print check_plain( $paymentmethod[ 'name' ] ); ?></a><?php endforeach; ?></td>
</tr>
</tfoot>
</table>

Loading…
Cancel
Save