Advertisement
roniewill

cancelarRecorrente()

Sep 4th, 2017
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. public function cancelarRecorrente($id_fatura, $id_usuario, $is_builderall = false) {
  2.  
  3.         $dados = array(
  4.             'id = ?' => $id_fatura,
  5.             'paga = ?' => 1,
  6.             'recorrente_ativo = ?' => 1,
  7.             'paypal_subscr_id IS NOT NULL OR paypal_preapproval_key IS NOT NULL'
  8.         );
  9.         if (!empty($id_usuario))
  10.             $dados['id_usuario = ?'] = $id_usuario;
  11.  
  12.         $fatura = $this->fetchRow($dados);
  13.         if (empty($fatura))
  14.             throw new Exception('fatura_nao_encontrada');
  15.  
  16.         if ($fatura['paypal_preapproval_key'] && 1==0) {
  17.             $result = $this->payPreapproval($fatura);
  18.  
  19.             if($result == 'error canceled') {
  20.                 $fatura->recorrente_ativo = 0;
  21.                 $fatura->save();
  22.                 return true;
  23.             } else {
  24.                 throw new Exception('error_change_status_paypal');
  25.             }
  26.         } else {
  27.  
  28.             $user_api = null;
  29.             $modelFaturaNotificacao = new Sistema_Model_DbTable_Office_FaturaNotificacao();
  30.             $notificacao = $modelFaturaNotificacao->fetchRow([
  31.                 'id_fatura = ?' => $id_fatura,
  32.                 'txn_type = ?' => 'subscr_signup',
  33.             ]);
  34.  
  35.             if (!empty($notificacao['post'])) {
  36.                 $post = Zend_Json::decode($notificacao['post']);
  37.                 if ($post['business'] == 'contact@pagamentoparalelo.com')
  38.                     $user_api = 'contact@pagamentoparalelo.com';
  39.             }
  40.  
  41.             if(empty($user_api)) {
  42.                 $user_api = 'contact@pagamentoparalelo.com';
  43.             }
  44.  
  45.             if($is_builderall) {
  46.                 $user_api = 'contact@ebusiness4us.com';
  47.             }
  48.  
  49.             $res = My_Paypal_Standard::change_subscription_status($fatura['paypal_subscr_id'], 'Cancel', null, $user_api);
  50.         }
  51.  
  52.         if ($res['ACK'] == 'Success') {
  53.             $fatura->recorrente_ativo = 0;
  54.             $fatura->save();
  55.         } else {
  56.             throw new Exception('error_change_status_paypal');
  57.         }
  58.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement