Skip to content

Commit

Permalink
➕ implements payment with multi methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ThiagoBarradas committed Jan 8, 2018
1 parent 5fdd75f commit 5a65883
Show file tree
Hide file tree
Showing 70 changed files with 5,645 additions and 167 deletions.
8 changes: 8 additions & 0 deletions .idea/MundiPagg.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

795 changes: 795 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Api/CreditCardRequestDataProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getInstallmentCount();
* @return int
*/
public function getSaveCard();

/**
* @return string
*/
Expand Down
14 changes: 14 additions & 0 deletions Api/Data/CardsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface CardsInterface
const LAST_FOUR_NUMBERS = 'last_four_numbers';
const CREATED_AT = 'created_at';
const UPDATED_AT = 'updated_at';
const BRAND = 'brand';

/**
* Get id
Expand Down Expand Up @@ -103,4 +104,17 @@ public function getUpdatedAt();
* @return \MundiPagg\MundiPagg\Api\Data\CardsInterface
*/
public function setUpdatedAt($updatedAt);

/**
* Get grand
* @return string|null
*/
public function getBrand();

/**
* Set brand
* @param string $brand
* @return \MundiPagg\MundiPagg\Api\Data\CardsInterface
*/
public function setBrand($brand);
}
67 changes: 67 additions & 0 deletions Api/TwoCreditCardRequestDataProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/**
* Class CreateBilletCreditCardDataProviderInterface
*
* @author MundiPagg Embeddables Team <[email protected]>
* @copyright 2017 MundiPagg (http://www.mundipagg.com)
* @license http://www.mundipagg.com Copyright
*
* @link http://www.mundipagg.com
*/

namespace MundiPagg\MundiPagg\Api;


interface TwoCreditCardRequestDataProviderInterface extends BaseRequestDataProviderInterface
{

/**
* @return int
*/
public function getInstallmentCount();

/**
* @return int
*/
public function getSaveCard();

/**
* @return string
*/
public function getBilletCreditCardOperation();

/**
* @return string
*/
public function getBilletCreditCardBrand();

/**
* @return string
*/
public function getBilletCreditCardNumber();

/**
* @return string
*/
public function getExpMonth();

/**
* @return string
*/
public function getExpYear();

/**
* @return string
*/
public function getHolderName();

/**
* @return string
*/
public function getSecurityCode();

/**
* @return string
*/
public function getIsOneDollarAuthEnabled();
}
15 changes: 15 additions & 0 deletions Block/Payment/Info/BilletCreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ public function getCardNumber()
return '**** **** **** ' . $this->getInfo()->getCcLast4();
}

public function getCardLast4()
{
return '**** **** **** ' . $this->getInfo()->getAdditionalInformation('cc_last_4');
}

public function getCcBrand()
{
return $this->getInfo()->getAdditionalInformation('cc_type');
}

public function getTitle()
{
return $this->getInfo()->getAdditionalInformation('method_title');
Expand All @@ -65,6 +75,11 @@ public function getCcAmount()
return $this->getInfo()->getAdditionalInformation('cc_cc_amount');
}

public function getCcAmountWithTax()
{
return $this->getInfo()->getAdditionalInformation('cc_cc_amount') + $this->getInfo()->getAdditionalInformation('cc_cc_tax_amount') / 100;
}

public function getBilletAmount()
{
return $this->getInfo()->getAdditionalInformation('cc_billet_amount');
Expand Down
10 changes: 10 additions & 0 deletions Block/Payment/Info/CreditCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ public function getCardNumber()
return '**** **** **** ' . $this->getInfo()->getCcLast4();
}

public function getCardLast4()
{
return '**** **** **** ' . $this->getInfo()->getAdditionalInformation('cc_last_4');
}

public function getCcBrand()
{
return $this->getInfo()->getAdditionalInformation('cc_type');
}

public function getTitle()
{
return $this->getInfo()->getAdditionalInformation('method_title');
Expand Down
84 changes: 84 additions & 0 deletions Block/Payment/Info/TwoCreditCard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* Class Billet
*
* @author Webjump Core Team <[email protected]>
* @copyright 2016 Webjump (http://www.webjump.com.br)
* @license http://www.webjump.com.br Copyright
*
* @link http://www.webjump.com.br
*/

namespace MundiPagg\MundiPagg\Block\Payment\Info;

use Magento\Payment\Block\Info\Cc;

class TwoCreditCard extends Cc
{
const TEMPLATE = 'MundiPagg_MundiPagg::info/twoCreditCard.phtml';

public function _construct()
{
$this->setTemplate(self::TEMPLATE);
}

public function getCcType()
{
return $this->getCcTypeName();
}

public function getCardNumber()
{
return '**** **** **** ' . $this->getInfo()->getCcLast4();
}

public function getTitle()
{
return $this->getInfo()->getAdditionalInformation('method_title');
}

public function getInstallments()
{
return $this->getInfo()->getAdditionalInformation('cc_installments');
}

public function getInstallmentsFirstCard()
{
return $this->getInfo()->getAdditionalInformation('cc_installments_first');
}

public function getCcTypeFirst()
{
return $this->getInfo()->getAdditionalInformation('cc_type_first');
}

public function getFirstCardAmount()
{
return $this->getInfo()->getAdditionalInformation('cc_first_card_amount') + $this->getInfo()->getAdditionalInformation('cc_first_card_tax_amount');
}

public function getFirstCardLast4()
{
return '**** **** **** ' . $this->getInfo()->getAdditionalInformation('cc_last_4_first');
}

public function getInstallmentsSecondCard()
{
return $this->getInfo()->getAdditionalInformation('cc_installments_second');
}

public function getCcTypeSecond()
{
return $this->getInfo()->getAdditionalInformation('cc_type_second');
}

public function getSecondCardAmount()
{
return $this->getInfo()->getAdditionalInformation('cc_second_card_amount') + $this->getInfo()->getAdditionalInformation('cc_second_card_tax_amount');
}

public function getSecondCardLast4()
{
return '**** **** **** ' . $this->getInfo()->getAdditionalInformation('cc_last_4_second');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,18 @@ protected function createNewRequest($requestDataProvider)

$capture = $this->getConfigBilletCreditCard()->getPaymentAction() == '‌authorize_capture' ? true : false;

$billetAmount = $quote->getPayment()->getCcBilletAmount() * 100;

if ($payment->getAdditionalInformation('cc_saved_card')) {

$model = $this->getCardsFactory();
$cardCollection = $model->getCollection()->addFieldToFilter('id',array('eq' => $payment->getAdditionalInformation('cc_saved_card')))->getFirstItem();


$order->payments = [
[
'payment_method' => 'credit_card',
'amount' => $quote->getPayment()->getCcCcAmount() * 100,
'amount' => $requestDataProvider->getAmountInCents() - $billetAmount,
'credit_card' => [
'recurrence' => false,
'installments' => $requestDataProvider->getInstallmentCount(),
Expand All @@ -381,7 +384,7 @@ protected function createNewRequest($requestDataProvider)
[
'payment_method' => 'boleto',
'capture' => $capture,
'amount' => $quote->getPayment()->getCcBilletAmount() * 100,
'amount' => $billetAmount,
'boleto' => [
'bank' => '033',
'instructions' => 'Pagar até o vencimento',
Expand All @@ -395,7 +398,7 @@ protected function createNewRequest($requestDataProvider)
$order->payments = [
[
'payment_method' => 'credit_card',
'amount' => $quote->getPayment()->getCcCcAmount() * 100,
'amount' => $requestDataProvider->getAmountInCents() - $billetAmount,
'credit_card' => [
'recurrence' => false,
'installments' => $requestDataProvider->getInstallmentCount(),
Expand All @@ -418,7 +421,7 @@ protected function createNewRequest($requestDataProvider)
[
'payment_method' => 'boleto',
'capture' => $capture,
'amount' => $quote->getPayment()->getCcBilletAmount() * 100,
'amount' => $billetAmount,
'boleto' => [
'bank' => '033',
'instructions' => 'Pagar até o vencimento',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ protected function createNewRequest($requestDataProvider)

$payment = $quote->getPayment();



$order = $this->getOrderRequest();

$capture = $this->getConfigCreditCard()->getPaymentAction() == '‌authorize_capture' ? true : false;
Expand All @@ -358,7 +360,7 @@ protected function createNewRequest($requestDataProvider)
[
'payment_method' => 'credit_card',
'credit_card' => [
'amount' => $quote->getGrandTotal() * 100,
'amount' => $requestDataProvider->getAmountInCents(),
'recurrence' => false,
'installments' => $requestDataProvider->getInstallmentCount(),
'statement_descriptor' => 'Mundipagg Online',
Expand All @@ -384,8 +386,8 @@ protected function createNewRequest($requestDataProvider)
$order->payments = [
[
'payment_method' => 'credit_card',
'amount' => $requestDataProvider->getAmountInCents(),
'credit_card' => [
'amount' => $quote->getGrandTotal() * 100,
'recurrence' => false,
'installments' => $requestDataProvider->getInstallmentCount(),
'statement_descriptor' => 'Mundipagg Online',
Expand Down Expand Up @@ -474,8 +476,7 @@ protected function createNewRequest($requestDataProvider)
{
$customer = $response->customer;

$this->setCardToken($requestDataProvider, $customer, $quote);

$this->setCardToken($payment, $customer, $quote);
}

} catch (\MundiAPILib\Exceptions\ErrorException $error) {
Expand All @@ -496,15 +497,15 @@ public function getCardRequest()
return new \MundiAPILib\Models\CreateCardRequest();
}

protected function setCardToken($requestDataProvider, $customer, $quote)
protected function setCardToken($payment, $customer, $quote)
{
$request = $this->getCardRequest();

$request->number = $requestDataProvider->getCreditCardNumber();
$request->holderName = $requestDataProvider->getHolderName();
$request->expMonth = $requestDataProvider->getExpMonth();
$request->expYear = $requestDataProvider->getExpYear();
$request->cvv = $requestDataProvider->getSecurityCode();
$request->number = $payment->getCreditCardNumber();
$request->holderName = $payment->getHolderName();
$request->expMonth = $payment->getExpMonth();
$request->expYear = $payment->getExpYear();
$request->cvv = $payment->getSecurityCode();
$request->billingAddress = [
'street' => $quote->getBillingAddress()->getStreetLine(1),
'number' => $quote->getBillingAddress()->getStreetLine(2) . ' ' . $quote->getBillingAddress()->getStreetLine(3),
Expand All @@ -524,20 +525,21 @@ protected function setCardToken($requestDataProvider, $customer, $quote)
];

$result = $this->createCard($customer, $request);
$this->setCard($quote, $customer, $requestDataProvider, $result);
$this->setCard($quote, $customer, $payment, $result);


return $this;
}

protected function setCard($quote, $customer, $requestDataProvider, $result)
protected function setCard($quote, $customer, $payment, $result)
{
try {
$cards = $this->getCardsFactory();
$cards->setCustomerId($quote->getCustomerId());
$cards->setCardToken($result->id);
$cards->setCardId($customer->id);
$cards->setLastFourNumbers(substr($requestDataProvider->getCreditCardNumber(), -4));
$cards->setLastFourNumbers(substr($payment->getCreditCardNumber(), -4));
$cards->setBrand($payment->getCcType());
$cards->setCreatedAt(date("Y-m-d H:i:s"));
$cards->setUpdatedAt(date("Y-m-d H:i:s"));
$cards->save();
Expand Down
Loading

0 comments on commit 5a65883

Please sign in to comment.