show PaymentItems

master
Marek Isalski 9 years ago
parent c15369b234
commit 7fbd49d6fb

@ -49,6 +49,12 @@ function fulcrm_shoppingcart_menu() {
'access callback' => 'user_access', 'access callback' => 'user_access',
'access arguments' => array('access content'), 'access arguments' => array('access content'),
); );
$items[ 'fulcrm/checkout/coupon/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_coupon',
'page arguments' => array(3,4),
'type' => MENU_CALLBACK,
'access callback' => 'user_access',
'access arguments' => array('access content'),
);
$items[ 'fulcrm/checkout/success/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout_success', $items[ 'fulcrm/checkout/success/%/%' ] = array( 'page callback' => 'fulcrm_shoppingcart_checkout_success',
'page arguments' => array(3,4), 'page arguments' => array(3,4),
'type' => MENU_CALLBACK, 'type' => MENU_CALLBACK,
@ -81,7 +87,7 @@ function fulcrm_shoppingcart_theme( $existing, $type, $theme, $path ) {
'fulcrm_shoppingcart_cart_item' => array( 'variables' => array( 'shoppingitem' => null ), // data returned from fulcrm API 'fulcrm_shoppingcart_cart_item' => array( 'variables' => array( 'shoppingitem' => null ), // data returned from fulcrm API
'template' => 'fulcrm_shoppingcart_cart_item', 'template' => 'fulcrm_shoppingcart_cart_item',
), ),
'fulcrm_shoppingcart_transaction_checkout' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API 'fulcrm_shoppingcart_transaction_checkout' => array( 'variables' => array( 'transaction' => null, 'use_coupon_url' => null ), // data returned from fulcrm API
'template' => 'fulcrm_shoppingcart_transaction_checkout', 'template' => 'fulcrm_shoppingcart_transaction_checkout',
), ),
'fulcrm_shoppingcart_transaction_items' => array( 'variables' => array( 'items' => null ), // data returned from fulcrm API 'fulcrm_shoppingcart_transaction_items' => array( 'variables' => array( 'items' => null ), // data returned from fulcrm API
@ -90,6 +96,9 @@ function fulcrm_shoppingcart_theme( $existing, $type, $theme, $path ) {
'fulcrm_shoppingcart_transaction_item' => array( 'variables' => array( 'item' => null ), // data returned from fulcrm API 'fulcrm_shoppingcart_transaction_item' => array( 'variables' => array( 'item' => null ), // data returned from fulcrm API
'template' => 'fulcrm_shoppingcart_transaction_item', 'template' => 'fulcrm_shoppingcart_transaction_item',
), ),
'fulcrm_shoppingcart_transaction_payment' => array( 'variables' => array( 'item' => null ), // data returned from fulcrm API
'template' => 'fulcrm_shoppingcart_transaction_payment',
),
'fulcrm_shoppingcart_transaction_complete' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API 'fulcrm_shoppingcart_transaction_complete' => array( 'variables' => array( 'transaction' => null ), // data returned from fulcrm API
'template' => 'fulcrm_shoppingcart_transaction_complete', 'template' => 'fulcrm_shoppingcart_transaction_complete',
), ),
@ -142,6 +151,11 @@ function fulcrm_shoppingcart_get_session_cart( $create = true ) {
} }
} }
function fulcrm_shoppingcart_coupon_url( $transaction_id ) {
$hmac = fulcrm_crypto_object_id_hmac( 'transaction', $transaction_id );
return url( 'fulcrm/checkout/coupon/' . $transaction_id . '/' . $hmac );
}
function fulcrm_shoppingcart_buy_url( $product_id ) { function fulcrm_shoppingcart_buy_url( $product_id ) {
$hmac = fulcrm_crypto_object_id_hmac( 'product', $product_id ); $hmac = fulcrm_crypto_object_id_hmac( 'product', $product_id );
return url( 'fulcrm/buy/' . $product_id . '/' . $hmac ); return url( 'fulcrm/buy/' . $product_id . '/' . $hmac );
@ -456,6 +470,60 @@ function fulcrm_shoppingcart_cart() {
return theme( 'fulcrm_shoppingcart_cart', array( 'cart' => $cart ) ); return theme( 'fulcrm_shoppingcart_cart', array( 'cart' => $cart ) );
} }
function fulcrm_shoppingcart_coupon_form_submit( $form, &$form_state ) {
$transaction_id = $form_state[ 'fulcrm_shoppingcart' ][ 'transaction_id' ];
$coupon_code = $form_state[ 'values' ][ 'coupon_code' ];
if ( $coupon_code && $transaction_id ) {
$paymentitem_data = fulcrm_apiv2_POST( 'transaction/' . $transaction_id . '/coupon/', array(), array( 'coupon_code' => $coupon_code,
'expand' => implode( ',', array( 'd' ) ) ) );
if ( $paymentitem_data[ 'success' ] ) {
if ( count( $paymentitem_data[ 'data' ] ) ) {
drupal_set_message( t('Coupon code applied!'), 'info' );
} else {
drupal_set_message( t('That is not a valid coupon code.'), 'warning' );
}
} else {
drupal_set_message( t('There was a problem redeeming your coupon.'), 'error' );
}
} else {
drupal_set_message( t('That is not a valid coupon code.'), 'error' );
}
drupal_goto( 'fulcrm/checkout' );
}
function fulcrm_shoppingcart_coupon_form( $form, &$form_state, $transaction_id ) {
$form_state[ 'fulcrm_shoppingcart' ][ 'transaction_id' ] = $transaction_id;
$form = array();
$form[ 'title_coupon' ] = array( '#type' => 'markup',
'#markup' => '<h1>' . t('Redeem Coupon') . '</h1>',
);
$form[ 'coupon_code' ] = array( '#type' => 'textfield',
'#title' => t('Coupon Code'),
'#description' => t('Please carefully type the coupon code here. Coupons can only be used once, and are non-refundable.'),
);
$form[ 'actions' ] = array( '#type' => 'actions' );
$form[ 'actions' ][ 'save' ] = array( '#type' => 'submit',
'#value' => t('Use Coupon'),
'#submit' => array( 'fulcrm_shoppingcart_coupon_form_submit' ),
);
return $form;
}
function fulcrm_shoppingcart_coupon( $transaction_id, $hmac ) {
if ( fulcrm_crypto_check_object_id_hmac( 'transaction', $transaction_id, $hmac ) ) {
return drupal_get_form( 'fulcrm_shoppingcart_coupon_form', $transaction_id );
} else {
drupal_goto( 'fulcrm/checkout' );
}
}
function fulcrm_shoppingcart_checkout() { function fulcrm_shoppingcart_checkout() {
$cart = fulcrm_shoppingcart_get_session_cart( false ); $cart = fulcrm_shoppingcart_get_session_cart( false );
if ( $cart && array_key_exists( 'url', $cart ) ) { if ( $cart && array_key_exists( 'url', $cart ) ) {
@ -472,9 +540,12 @@ function fulcrm_shoppingcart_checkout() {
$transaction_data2 = fulcrm_apiv2_PATCH( $transaction_data[ 'data' ][ 'url' ], $transaction_data2 = fulcrm_apiv2_PATCH( $transaction_data[ 'data' ][ 'url' ],
$transaction_push, $query = array( 'expand' => implode( ',', array( 'd', $transaction_push, $query = array( 'expand' => implode( ',', array( 'd',
'lineitems', 'lineitems',
'paymentitems',
) ) ) ); ) ) ) );
if ( $transaction_data2[ 'success' ] ) { if ( $transaction_data2[ 'success' ] ) {
return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data2[ 'data' ] ) ); return theme( 'fulcrm_shoppingcart_transaction_checkout', array( 'transaction' => $transaction_data2[ 'data' ],
'use_coupon_url' => fulcrm_shoppingcart_coupon_url( $transaction_data[ 'data' ][ 'id' ] ),
) );
} }
return 'problem 3'; return 'problem 3';
} }

@ -15,17 +15,19 @@
</tbody> </tbody>
<tfoot> <tfoot>
<?php foreach ( $transaction[ 'paymentitems' ] as $paymentitem ) { if ( !$paymentitem[ 'fee' ] ) { print theme( 'fulcrm_shoppingcart_transaction_payment', array( 'item' => $paymentitem ) ); } } ?>
<tr> <tr>
<th colspan="3"> <th colspan="3">
Total Total
</th> </th>
<th class="text-right"> <th class="text-right">
<?php $any = false; ?> <?php $any = false; ?>
<?php if ( count( $transaction[ '_price' ][ 'total' ] ) ): ?> <?php if ( count( $transaction[ '_price' ][ 'outstanding' ] ) ): ?>
<?php foreach ( $transaction[ '_price' ][ 'total' ] as $currency => $price ): ?> <?php foreach ( $transaction[ '_price' ][ 'outstanding' ] as $currency => $price ): ?>
<?php if ( $price[ 'gross' ] ): ?> <?php if ( $price[ 'balance' ] > 0 ): ?>
<?php $any = true; ?> <?php $any = true; ?>
<div><?php print $currency . ' ' . $price[ 'format_gross' ]; ?></div> <div><?php print $currency . ' ' . $price[ 'format_balance' ]; ?></div>
<?php endif; ?> <?php endif; ?>
<?php endforeach; ?> <?php endforeach; ?>
<?php endif; ?> <?php endif; ?>

@ -0,0 +1,4 @@
<tr>
<td colspan="3"><?php print check_plain( $item[ 'name' ] ); ?></td>
<td class="text-right">&ndash;<?php print $item[ '_price' ][ 'format_total' ]; ?></td>
</tr>
Loading…
Cancel
Save