-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from aune-io/feature/vault_source
Feature/vault source
- Loading branch information
Showing
41 changed files
with
1,361 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,9 @@ | |
|
||
use Magento\Payment\Block\Form\Cc; | ||
|
||
/** | ||
* @codeCoverageIgnore | ||
*/ | ||
class Form extends Cc | ||
{ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
namespace Aune\Stripe\Gateway\Helper; | ||
|
||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
use Aune\Stripe\Model\Adapter\StripeAdapter; | ||
|
||
class TokenProvider | ||
{ | ||
const ATTRIBUTE_CODE = 'stripe_id'; | ||
const TOKEN_TYPE_CUSTOMER = 'customer'; | ||
const TOKEN_TYPE_SOURCE = 'source'; | ||
|
||
/** | ||
* @var CustomerRepositoryInterface | ||
*/ | ||
private $customerRepository; | ||
|
||
/** | ||
* @var StripeAdapter | ||
*/ | ||
private $stripeAdapter; | ||
|
||
/** | ||
* @param CustomerRepositoryInterface $customerRepository | ||
* @param StripeAdapter $stripeAdapter | ||
*/ | ||
public function __construct( | ||
CustomerRepositoryInterface $customerRepository, | ||
StripeAdapter $stripeAdapter | ||
) { | ||
$this->customerRepository = $customerRepository; | ||
$this->stripeAdapter = $stripeAdapter; | ||
} | ||
|
||
/** | ||
* Returns the Stripe customer id given the Magento customer id | ||
*/ | ||
public function getCustomerStripeId(int $magentoCustomerId) | ||
{ | ||
$stripeCustomerId = null; | ||
|
||
try { | ||
$customer = $this->customerRepository->getById($magentoCustomerId); | ||
$attribute = $customer->getCustomAttribute(self::ATTRIBUTE_CODE); | ||
if ($attribute instanceof \Magento\Framework\Api\AttributeValue) { | ||
$stripeCustomerId = $attribute->getValue(); | ||
} | ||
} catch (NoSuchEntityException $ex) { } | ||
|
||
return $stripeCustomerId; | ||
} | ||
|
||
/** | ||
* Saves the Stripe customer id against a Magento customer | ||
*/ | ||
public function setCustomerStripeId(int $magentoCustomerId, string $stripeCustomerId) | ||
{ | ||
try { | ||
$customer = $this->customerRepository->getById($magentoCustomerId); | ||
$customer->setCustomAttribute(self::ATTRIBUTE_CODE, $stripeCustomerId); | ||
$this->customerRepository->save($customer); | ||
} catch (NoSuchEntityException $ex) { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.