partial #2308 - balanced payment

This commit is contained in:
Daniel Camargo 2014-01-28 19:40:21 -02:00
parent 53264968dc
commit 1f8186f05e
9 changed files with 154 additions and 135 deletions

View File

@ -398,6 +398,11 @@ class Crunchbutton_App extends Cana_App {
$config['env'] = $this->env();
$config['ab'] = json_decode($this->auth()->get('ab'));
// export the processor info
$config[ 'processor' ][ 'type' ] = Crunchbutton_User_Payment_Type::processor();
$config[ 'processor' ][ 'stripe' ] = c::config()->stripe->{c::getEnv()}->{'public'};
$config[ 'processor' ][ 'balanced' ] = c::balanced()->uri;
if (!$this->auth()->get('loc_lat')) {
$geo = new Crunchbutton_Geo([
'adapter' => 'Geoip_Binary',

View File

@ -38,6 +38,7 @@
<script src="/assets/js/notification.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/js/order.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/js/log.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/js/tokenizeCard.js?v=<?=Cana_Util::gitVersion()?>"></script>
<!-- AngularJS Controllers -->
<script src="/assets/js/controllers.js?v=<?=Cana_Util::gitVersion()?>"></script>

View File

@ -88,21 +88,4 @@ $(function() {
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<? endif ; ?>
<?php
switch (Crunchbutton_User_Payment_Type::processor()) {
case 'stripe':
?><script src="/assets/js/tokenizeCard.stripe.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script type="text/javascript">Stripe.setPublishableKey('<?=c::config()->stripe->{c::getEnv()}->{'public'}?>');</script><?php
break;
case 'balanced':
default:
?>
<script src="/assets/js/tokenizeCard.balanced.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script type="text/javascript">balanced.init('<?=c::balanced()->uri?>');</script>
<?php
break;
}
?>
<? endif ; ?>

View File

@ -4,17 +4,11 @@
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-animate.min.js"></script>
<?php
switch (Crunchbutton_User_Payment_Type::processor()) {
case 'stripe':
?><script type="text/javascript" src="//js.stripe.com/v2/"></script><?php
break;
case 'balanced':
default:
?><script src="//js.balancedpayments.com/v1/balanced.js"></script><?php
break;
}
?>
<!-- Payment stuff -->
<script type="text/javascript" src="//js.stripe.com/v2/"></script>
<script src="//js.balancedpayments.com/v1/balanced.js"></script>
<? if (c::config()->bundle) : ?>
<script src="/assets/js/bundle.js?v=<?=Cana_Util::gitVersion()?>&s=app"></script>
<? else : ?>

View File

@ -4,6 +4,9 @@
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-animate.min.js"></script>
<!-- Payment stuff -->
<script type="text/javascript" src="//js.stripe.com/v2/"></script>
<script src="//js.balancedpayments.com/v1/balanced.js"></script>
<? if (c::config()->bundle) : ?>

View File

@ -727,6 +727,20 @@ App.init = function(config) {
},10);
}
// Init the processor
var processor = ( App.config.processor && App.config.processor.type ) ? App.config.processor.type : false;
switch( processor ){
case 'stripe':
Stripe.setPublishableKey( App.config.processor.stripe );
break;
case 'balanced':
balanced.init( App.config.processor.balanced );
break;
default:
console.log( 'Processor error::', App.config.processor );
break;
}
$(window).trigger('nginit');
};

View File

@ -1,55 +0,0 @@
App.tokenizeCard = function(card, complete) {
balanced.card.create(card, function(response) {
var res = {
status: false
};
switch (response.status) {
case 201:
res.status = true;
res.id = response.data.id;
res.uri = response.data.uri;
res.card_type = response.data.card_type;
res.lastfour = response.data.last_four;
res.month = card.expiration_month;
res.year = card.expiration_year;
break;
case 400:
res.error = 'Missing fields';
break;
case 402:
res.error = 'Unable to authorize';
break;
case 404:
res.error = 'Unexpected error';
break;
case 409:
res.error = 'Unable to validate';
break;
case 500:
res.error = 'Error processing payment';
break;
// a lack of any response from the ios sdk
case 999:
res.error = 'Unable to reach payment server';
break;
// a response from the ios sdk that was both ilformated and didnt not validate
case 666:
res.error = 'Unable to validate your card';
break;
// who knows wtf this is
default:
res.error = 'Unable to validate your card at this time';
break;
}
console.debug('Balanced tokenization response',response);
complete(res);
} );
};

View File

@ -0,0 +1,125 @@
App.tokenizeCard = function( card, complete ) {
var processor = ( App.config.processor && App.config.processor.type ) ? App.config.processor.type : false;
switch( processor ){
case 'stripe':
App.tokenizeCard_stripe( card, complete );
break;
case 'balanced':
App.tokenizeCard_balanced( card, complete );
break;
default:
console.log( 'Processor error::', App.config.processor );
break;
}
};
App.tokenizeCard_stripe = function( card, complete ) {
var res = { status: false };
var card = { number: card.card_number, exp_month: card.expiration_month, exp_year: card.expiration_year };
Stripe.card.createToken( card , function( status, response ){
if ( response.error ) {
switch( response.error.code ){
case 'incorrect_number':
res.error = 'This card number looks invalid';
break;
case 'invalid_number':
res.error = 'The card number is not a valid credit card number.';
break;
case 'invalid_expiry_month':
res.error = 'The card\'s expiration month is invalid.';
break;
case 'invalid_expiry_year':
res.error = 'The card\'s expiration year is invalid.';
break;
case 'invalid_cvc':
res.error = 'The card\'s security code is invalid.';
break;
case 'expired_card':
res.error = 'The card has expired.';
break;
case 'incorrect_cvc':
res.error = 'The card\'s security code is incorrect.';
break;
case 'card_declined':
res.error = 'The card was declined.';
break;
case 'processing_error':
res.error = 'An error occurred while processing the card.';
break;
default:
res.error = 'Unable to validate your card at this time';
break;
}
} else {
res = {
id : response.card.id,
uri: response.id,
lastfour: response.card.last4,
card_type: response.card.type,
month: response.card.exp_month,
year: response.card.exp_year,
status : true
}
}
complete( res );
} );
};
App.tokenizeCard_balanced = function(card, complete) {
console.log( 'call App.tokenizeCard_balanced' );
balanced.card.create(card, function(response) {
var res = {
status: false
};
switch (response.status) {
case 201:
res.status = true;
res.id = response.data.id;
res.uri = response.data.uri;
res.card_type = response.data.card_type;
res.lastfour = response.data.last_four;
res.month = card.expiration_month;
res.year = card.expiration_year;
break;
case 400:
res.error = 'Missing fields';
break;
case 402:
res.error = 'Unable to authorize';
break;
case 404:
res.error = 'Unexpected error';
break;
case 409:
res.error = 'Unable to validate';
break;
case 500:
res.error = 'Error processing payment';
break;
// a lack of any response from the ios sdk
case 999:
res.error = 'Unable to reach payment server';
break;
// a response from the ios sdk that was both ilformated and didnt not validate
case 666:
res.error = 'Unable to validate your card';
break;
// who knows wtf this is
default:
res.error = 'Unable to validate your card at this time';
break;
}
complete(res);
} );
};

View File

@ -1,51 +0,0 @@
App.tokenizeCard = function( card, complete ) {
var res = { status: false };
var card = { number: card.card_number, exp_month: card.expiration_month, exp_year: card.expiration_year };
Stripe.card.createToken( card , function( status, response ){
if ( response.error ) {
switch( response.error.code ){
case 'incorrect_number':
res.error = 'This card number looks invalid';
break;
case 'invalid_number':
res.error = 'The card number is not a valid credit card number.';
break;
case 'invalid_expiry_month':
res.error = 'The card\'s expiration month is invalid.';
break;
case 'invalid_expiry_year':
res.error = 'The card\'s expiration year is invalid.';
break;
case 'invalid_cvc':
res.error = 'The card\'s security code is invalid.';
break;
case 'expired_card':
res.error = 'The card has expired.';
break;
case 'incorrect_cvc':
res.error = 'The card\'s security code is incorrect.';
break;
case 'card_declined':
res.error = 'The card was declined.';
break;
case 'processing_error':
res.error = 'An error occurred while processing the card.';
break;
default:
res.error = 'Unable to validate your card at this time';
break;
}
} else {
res = {
id : response.card.id,
uri: response.id,
lastfour: response.card.last4,
card_type: response.card.type,
month: response.card.exp_month,
year: response.card.exp_year,
status : true
}
}
complete( res );
} );
};