Merge branch 'master' of github.com:crunchbutton/crunchbutton
This commit is contained in:
commit
b92d0a51a2
@ -7,6 +7,24 @@ class Controller_api_refund extends Crunchbutton_Controller_RestAccount {
|
|||||||
header('HTTP/1.1 401 Unauthorized');
|
header('HTTP/1.1 401 Unauthorized');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch ( c::getPagePiece( 2 ) ) {
|
||||||
|
case 'check':
|
||||||
|
$order = Order::uuid( c::getPagePiece( 3 ) );
|
||||||
|
if( $order->id_order ){
|
||||||
|
$order = $order->get( 0 );
|
||||||
|
if( $order->checkIfOrderWasRefunded() ){
|
||||||
|
echo json_encode(['status' => 'success']);
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'false']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
echo json_encode(['status' => 'false', 'errors' => 'invalid order id' ]);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
$order = Order::uuid( c::getPagePiece( 2 ) );
|
$order = Order::uuid( c::getPagePiece( 2 ) );
|
||||||
if( $order->id_order ){
|
if( $order->id_order ){
|
||||||
$status = $order->refund();
|
$status = $order->refund();
|
||||||
@ -18,5 +36,7 @@ class Controller_api_refund extends Crunchbutton_Controller_RestAccount {
|
|||||||
} else {
|
} else {
|
||||||
echo json_encode(['status' => 'false', 'errors' => 'invalid order id' ]);
|
echo json_encode(['status' => 'false', 'errors' => 'invalid order id' ]);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,12 +3,6 @@
|
|||||||
class Controller_Api_Test_Sandbox extends Cana_Controller {
|
class Controller_Api_Test_Sandbox extends Cana_Controller {
|
||||||
public function init(){
|
public function init(){
|
||||||
|
|
||||||
$order = Order::o( $_GET[ 'id_order' ] );
|
|
||||||
if( $order->id_order ){
|
|
||||||
echo '<pre>';var_dump( $order->refund() );exit();;
|
|
||||||
} else {
|
|
||||||
echo '<pre>';var_dump( 'error' );exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2998,6 +2998,29 @@ class Crunchbutton_Order extends Crunchbutton_Order_Trackchange {
|
|||||||
return $out;
|
return $out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function checkIfOrderWasRefunded( $force = false ){
|
||||||
|
if( $this->refunded && !$force ){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if( $this->txn ){
|
||||||
|
$env = ( $this->env == 'live' ) ? 'live' : 'dev';
|
||||||
|
$api_key = c::config()->balanced->{$env}->secret;
|
||||||
|
Balanced\Settings::$api_key = $api_key;
|
||||||
|
$url = '/debits/' . $this->txn . '/refunds';
|
||||||
|
$refund = json_decode( json_encode( ( object ) Balanced\Refund::get( $url ) ) );
|
||||||
|
if( $refund && $refund->status && $refund->status == 'succeeded' ){
|
||||||
|
$this->refunded = 1;
|
||||||
|
$this->save();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function save() {
|
public function save() {
|
||||||
$new = $this->id_order ? false : true;
|
$new = $this->id_order ? false : true;
|
||||||
|
|
||||||
|
|||||||
@ -59,8 +59,13 @@ $permissionSupportView = c::admin()->permission()->check(['global','support-all'
|
|||||||
<? if ($order->refunded) : ?>
|
<? if ($order->refunded) : ?>
|
||||||
REFUNDED
|
REFUNDED
|
||||||
<? else : ?>
|
<? else : ?>
|
||||||
<a href="javascript:;" class="refund" data-charged="<?php echo $order->charged(); ?>" data-gift="<?php if( $order->chargedByCredit() > 0 ){ echo $order->chargedByCredit(); } else { echo '0'; } ?>" data-uuid="<?=$order->uuid?>">REFUND
|
<a href="javascript:;" class="refund was-refunded-<?=$order->uuid?>" data-charged="<?php echo $order->charged(); ?>" data-gift="<?php if( $order->chargedByCredit() > 0 ){ echo $order->chargedByCredit(); } else { echo '0'; } ?>" data-uuid="<?=$order->uuid?>">REFUND
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<a href="javascript:;" class="check-refunded check-was-refunded-<?=$order->uuid?>" data-uuid="<?=$order->uuid?>">Check if it was refunded</a>
|
||||||
|
|
||||||
<? endif ; ?>
|
<? endif ; ?>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
|||||||
@ -886,6 +886,57 @@ App.orders = {
|
|||||||
location.href = '/orders/content?' + jQuery.param(params);
|
location.href = '/orders/content?' + jQuery.param(params);
|
||||||
},
|
},
|
||||||
createEvents: function(){
|
createEvents: function(){
|
||||||
|
|
||||||
|
$(document).on('click', '.check-refunded', function() {
|
||||||
|
|
||||||
|
var el = $(this);
|
||||||
|
|
||||||
|
$( '.refunded-' + el.attr('data-uuid') ).show();
|
||||||
|
|
||||||
|
el.html(' Checking <i class="icon-spinner icon-spin"></i>');
|
||||||
|
|
||||||
|
var fail = function( result ){
|
||||||
|
console.log( result.responseText);
|
||||||
|
el.html('REFUND');
|
||||||
|
var er = result.errors ? "\n\n" + result.errors : 'See the console.log!';
|
||||||
|
alert('Refunding fail! ' + er);
|
||||||
|
}
|
||||||
|
$.ajax({
|
||||||
|
url: '/api/refund/check/' + el.attr('data-uuid'),
|
||||||
|
success: function( result ){
|
||||||
|
console.log('result',result);
|
||||||
|
try {
|
||||||
|
if( result.status && result.status == 'success' ){
|
||||||
|
$( '.was-refunded-' + el.attr('data-uuid') ).html( 'REFUNDED' );
|
||||||
|
el.hide();
|
||||||
|
var do_not_reimburse_driver = $( '.do_not_reimburse_driver-' + el.attr('data-uuid') );
|
||||||
|
do_not_reimburse_driver.show();
|
||||||
|
var do_not_reimburse_driver_value = ( do_not_reimburse_driver.attr( 'data-value' ) == 1 ? 0 : 1 );
|
||||||
|
do_not_reimburse_driver.attr( 'data-value', do_not_reimburse_driver_value );
|
||||||
|
if( do_not_reimburse_driver_value ){
|
||||||
|
do_not_reimburse_driver.find( 'span' ).html( '<i class="icon-check"></i>' );
|
||||||
|
} else {
|
||||||
|
do_not_reimburse_driver.find( 'span' ).html( '<i class="icon-check-empty"></i>' );
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if( result.status && result.status == 'false' ){
|
||||||
|
alert( 'Not refunded yet!' )
|
||||||
|
el.html('Check if it was refunded');
|
||||||
|
} else {
|
||||||
|
fail( result );
|
||||||
|
el.html('Check if it was refunded');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
fail( result );
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function( result ){
|
||||||
|
fail( result );
|
||||||
|
}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
$(document).on('click', '.refund', function() {
|
$(document).on('click', '.refund', function() {
|
||||||
|
|
||||||
var el = $(this);
|
var el = $(this);
|
||||||
@ -927,6 +978,7 @@ App.orders = {
|
|||||||
try {
|
try {
|
||||||
if( result.status && result.status == 'success' ){
|
if( result.status && result.status == 'success' ){
|
||||||
el.html('REFUNDED');
|
el.html('REFUNDED');
|
||||||
|
$( '.check-was-refunded-' + el.attr('data-uuid') ).hide();
|
||||||
} else {
|
} else {
|
||||||
fail( result );
|
fail( result );
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user