Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Como configurar as parcelas [ installments ]? #149

Open
thiivalente opened this issue Oct 24, 2019 · 5 comments
Open

Como configurar as parcelas [ installments ]? #149

thiivalente opened this issue Oct 24, 2019 · 5 comments

Comments

@thiivalente
Copy link
Contributor

Bem, gostaria de poder configurar as parcelas, podendo colocar o máximo de parcelas e até quantas parcelas o cliente poderia pagar sem juros.

Segundo documentação para colocar esses limites há 2 propriedades.

  1. maxInstallmentNoInterest
  2. noInterestInstallmentQuantity

Porém, tentei soltar diretamente no array que cria o checkout e não funcionou, alguém poderia me dizer como proceder?

@thiivalente
Copy link
Contributor Author

Descobri o que é necessário adicionar ao XML para conseguir fazer com que set a quantidade máximas de parcelas e quantos irei arcar com os juros

<paymentMethodConfigs>
    <paymentMethodConfig>
        <paymentMethod>
            <group>CREDIT_CARD</group>
        </paymentMethod>
        <configs>
            <config>
                <key>MAX_INSTALLMENTS_NO_INTEREST</key>
                <value>%s</value>
            </config>
            <config>
                <key>MAX_INSTALLMENTS_LIMIT</key>
                <value>%s</value>
            </config>
        </configs>
    </paymentMethodConfig>
</paymentMethodConfigs>

@Fuhrmann
Copy link

máximas de parcelas e quantos

Como você implementou?

@thiivalente
Copy link
Contributor Author

máximas de parcelas e quantos

Como você implementou?

Basicamente segui a forma de construção do XML no código, porém eu fiz de forma não genérica, pois fiz atendendo as necessidades do projeto por isso não abri PR para essa feature.

@douglastehling
Copy link

@thiivalente onde voce colocou esse xml?

@thiivalente
Copy link
Contributor Author

@douglastehling você configura isso no PaymentMethod, OBS: não esqueça do da interface.

    /**
     * Max Installments No Interest (Quantidade máxima de parcelas que não importam)
     * @var float
     */
    protected $maxInstallmentsNoInterest;

    /**
     * Get Max Installments Limit (Quantidade máxima de parcelas)
     * @var float
     */
    protected $maxInstallmentsLimit;

E também não esqueça de fazer os get e sets pro hydrate

/**
     * Get Max Installments No Interest (Quantidade máxima de parcelas que não importam)
     * @return float
     */
    public function getMaxInstallmentsNoInterest()
    {
        return $this->maxInstallmentsNoInterest;
    }

    /**
     * Get Max Installments Limit (Quantidade máxima de parcelas)
     * @return float
     */
    public function getMaxInstallmentsLimit()
    {
        return $this->maxInstallmentsLimit;
    }
// ...
**
     * Set Max Installments No Interest (Quantidade máxima de parcelas que não importam)
     * @param  float|null $method
     * @return float
     */
    public function setMaxInstallmentsNoInterest($maxInstallmentsNoInterest)
    {
        if(is_null($maxInstallmentsNoInterest)) { 
            return; 
        }
        $this->maxInstallmentsNoInterest = $maxInstallmentsNoInterest;
        return $this;
    }

/**
     * Set Max Installments No Interest (Quantidade máxima de parcelas que não importam)
     * @param  float|null $method
     * @return float
     */
    public function setMaxInstallmentsLimit($maxInstallmentsLimit)
    {
        if(is_null($maxInstallmentsLimit)) { 
            return; 
        }
        $this->maxInstallmentsLimit = $maxInstallmentsLimit;
        return $this;
    }

No ValidationRules coloque a validaçåo:

        'maxInstallmentsNoInterest' => 'numeric|between:2,16|',
        'maxInstallmentsLimit' => 'numeric|between:2,16|',

E por último, configurar dentro do XmlPaymentMethod no método:

    private function getPaymentMethodsXmlString(PaymentMethodInterface $paymentMethod)
    {
        // ...
        $configs = [];
        $hasConfigs = false;
        if(!is_null($paymentMethod->getMaxInstallmentsNoInterest()) && $paymentMethod->getMaxInstallmentsNoInterest() > 1) {
            $configs[] = $this->getInstallmentsNoInterestXmlString($paymentMethod->getMaxInstallmentsNoInterest());
            $hasConfigs = true;
        }
        if(!is_null($paymentMethod->getMaxInstallmentsLimit())) {
            $configs[] = $this->getMaxInstallmentsLimitXmlString($paymentMethod->getMaxInstallmentsNoInterest());
            $hasConfigs = true;
        }
        // ..
  }

  **
     * @param  float $maxInstallmentsNoInterest
     * @return string XML
     */
    private function getInstallmentsNoInterestXmlString(float $maxInstallmentsNoInterest)
    {
        $str = <<<XML
            <config>
                <key>MAX_INSTALLMENTS_NO_INTEREST</key>
                <value>%s</value>
            </config>
XML;
        return sprintf($str, $maxInstallmentsNoInterest);
    }

    /**
     * @return string XML
     */
    private function getMaxInstallmentsLimitXmlString(float $maxInstallmentsLimit)
    {
        $str = <<<XML
        <config>
            <key>MAX_INSTALLMENTS_LIMIT</key>
            <value>%s</value>
        </config>
XML;
    return sprintf($str, $maxInstallmentsLimit);
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants