Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function cancelarRecorrente($id_fatura, $id_usuario, $is_builderall = false) {
- $dados = array(
- 'id = ?' => $id_fatura,
- 'paga = ?' => 1,
- 'recorrente_ativo = ?' => 1,
- 'paypal_subscr_id IS NOT NULL OR paypal_preapproval_key IS NOT NULL'
- );
- if (!empty($id_usuario))
- $dados['id_usuario = ?'] = $id_usuario;
- $fatura = $this->fetchRow($dados);
- if (empty($fatura))
- throw new Exception('fatura_nao_encontrada');
- if ($fatura['paypal_preapproval_key'] && 1==0) {
- $result = $this->payPreapproval($fatura);
- if($result == 'error canceled') {
- $fatura->recorrente_ativo = 0;
- $fatura->save();
- return true;
- } else {
- throw new Exception('error_change_status_paypal');
- }
- } else {
- $user_api = null;
- $modelFaturaNotificacao = new Sistema_Model_DbTable_Office_FaturaNotificacao();
- $notificacao = $modelFaturaNotificacao->fetchRow([
- 'id_fatura = ?' => $id_fatura,
- 'txn_type = ?' => 'subscr_signup',
- ]);
- if (!empty($notificacao['post'])) {
- $post = Zend_Json::decode($notificacao['post']);
- if ($post['business'] == 'contact@pagamentoparalelo.com')
- $user_api = 'contact@pagamentoparalelo.com';
- }
- if(empty($user_api)) {
- $user_api = 'contact@pagamentoparalelo.com';
- }
- if($is_builderall) {
- $user_api = 'contact@ebusiness4us.com';
- }
- $res = My_Paypal_Standard::change_subscription_status($fatura['paypal_subscr_id'], 'Cancel', null, $user_api);
- }
- if ($res['ACK'] == 'Success') {
- $fatura->recorrente_ativo = 0;
- $fatura->save();
- } else {
- throw new Exception('error_change_status_paypal');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement