GithubHelp home page GithubHelp logo

Comments (6)

VictorRabelo avatar VictorRabelo commented on August 15, 2024 2

@gabrielpeixoto Muitooooooo obrigado cara! Sucessos ai

from gupayment.

gabrielpeixoto avatar gabrielpeixoto commented on August 15, 2024 1

Ahhh, no iugu tem um identificador do plano, é ele que deve ser passado por parâmetro.

Como está o identificador dos planos em https://alia.iugu.com/receive/plans? Clicando no plano, na página de detalhes mostra o identificador.
image

Esse valores que você deve passar ali onde passou o "PLANO PADRAO BOLETO"

from gupayment.

gabrielpeixoto avatar gabrielpeixoto commented on August 15, 2024

Olá @VictorRabelo tem como você colar o trecho de código de seu lado, para eu ver como estão as chamadas?

from gupayment.

VictorRabelo avatar VictorRabelo commented on August 15, 2024

Bom eu tenho dois arquivos que trata a requisição vinda do front, o primeiro é o App\Traits\UserTrait.php que contém esse método

`public function _userStore($request, $sing)
{

    try {
        $plan = '';
        if(!empty($request->type_payment) && $request->type_payment == 'boleto') {
            $plan = "PLANO PADRAO BOLETO";
        }elseif(!empty($request->type_payment) && $request->type_payment == 'cartao') {
            $plan = "PLANO PADRAO";
        }
        
        $url  = '';

        if(isset($request->new_account) && $request->new_account == 'no') {
            $user = User::where('cpf', $this->soNumero($request->cpf))->first();

            if(!empty($user)):
                // Criar cliente no Iugu
                //$user->createAsIuguCustomer();
                
                if($sing):
                    if($request->type_payment == 'cartao' && isset($request->credit_card) && is_array($request->credit_card)) {
                        $invoice = $user->singSubscription($plan, $request->type_payment, $request->credit_card);
                        if($invoice->status == 'paid') {
                            $this->activateAccount($user);
                        }
                        $url = $invoice->secure_url;
                    }else{
                        $invoice = $user->singSubscription($plan, $request->type_payment);
                        if($invoice->status == 'paid') {
                            $this->activateAccount($user);
                        }
                        $url = $invoice->secure_url;
                    }
                endif;

                if(empty($url)):
                    return response()->json(['status' => false, 'error' => 'Ocorreu um erro ao processar o pedido!'], 400);
                endif;

                return response()->json(['status' => true, 'user' => $user, 'url' => $url, 'message' => 'Recebemos seus dados com sucesso, e você será redirecionado!'], 200);
            endif;
        }else{

            $data = $this->prepareData($request);

            if(User::where('cpf', $data['cpf'])->first()) {
                return response()->json(['status' => false, 'error' => 'Já existe esse CPF cadastrado!'], 400);
            }

            $user = User::where('email', trim($request->email))->first();

            if(empty($user)) {

                $user = User::create($data);
                
				$user->role()->create([
                    'role' => 'guest'
                ]);
                					
            }

            if($user):
                if($sing):
                    if($request->type_payment == 'cartao' && isset($request->credit_card) && is_array($request->credit_card)) {
                        $invoice = $user->singSubscription($plan, $request->type_payment, $request->credit_card);

                        if($invoice->status == 'paid') {
                            $this->activateAccount($user);
                        }
                        $url = $invoice->secure_url;
                    }else{
                        $invoice = $user->singSubscription($plan, $request->type_payment);
                        if($invoice->status == 'paid') {
                            $this->activateAccount($user);
                        }
                        $url = $invoice->secure_url;
                    }
                endif;

                if(empty($url)):
                    return response()->json(['status' => false, 'error' => 'Ocorreu um erro ao processar o pedido!'], 400);
                endif;

                return response()->json(['status' => true, 'user' => $user, 'url' => $url, 'message' => 'Recebemos seus dados com sucesso, e você será redirecionado!'], 200);
            else:
                return response()->json(['status' => false, 'error' => 'Existe um erro, fale com o administrador!'], 400);
            endif;
        }
    } catch (\Exception $e) {
        
        return response()->json(['status' => false, 'error' => $e->getMessage()], 400);
    }
}`

PS: a variável $invoice recebe uma função que não esta retornando nada.

E o segundo é App\Models\User.php que contem esse trecho de código em especifico pois é o trecho que não está retornando nada,
`public function singSubscription($plan, $type, $credit_card = null)
{
$qtdDiasAteVencimento = 3;
$payable_with = '';

    if($type == 'boleto') {
        $payable_with = "bank_slip";
    }elseif($type == 'cartao') {
        $payable_with = "credit_card";
    }

    $subscriptionBuilder = $this->newSubscription($plan, $plan, [], ['payable_with' => $payable_with]);
    
    if($type == 'boleto') {
        $subscriptionBuilder->daysToExpire($qtdDiasAteVencimento );
    }


    $options = [
        'name'      => $this->name,
        'street'    => $this->rua,
        'district'  => $this->bairro,
        'cpf_cnpj'  => $this->cpf,
        'zip_code'  => $this->cep,
        'number'    => $this->numero,
    ];

    $creditCardToken = null;
    
    if(!empty($credit_card)) {
        $creditCardToken = $this->getToken($credit_card);
    }

    $signature = $subscriptionBuilder->create($creditCardToken, $options);
    
    if ($signature) {
        $invoice = null;
        if ($signature && isset($signature['recent_invoices'])):
            foreach ($signature->recent_invoices as $invoiceData):
                $invoice = $invoiceData;
            endforeach;
        endif;

        return $invoice;
    } else {
        $erros = $subscriptionBuilder->getLastError();
        
        if (is_array($erros)) {
            // array
        } else {
            // string
        }
    }
}`

from gupayment.

gabrielpeixoto avatar gabrielpeixoto commented on August 15, 2024

Uma dica. Aqui $this->newSubscription($plan, $plan, [], ['payable_with' => $payable_with]); usa um nome fixo no primeiro parâmetro em vez de $plan, pois isso aí só serve para quando você tem 2 assinaturas de produtos diferentes no site.

Sobre o erro ainda não consegui identificar, você conseguiria colar o trace completo aqui do erro?

from gupayment.

VictorRabelo avatar VictorRabelo commented on August 15, 2024

@gabrielpeixoto, Agora está me retornando uma resposta de dd(),
"plan_identifier" => array:1 [ 0 => "não é válido" ],

Creio eu que fica mais fácil de resolver esse problema

from gupayment.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.