Skip to content

Commit 74eb6b0

Browse files
Real initial release
1 parent d9c34c1 commit 74eb6b0

File tree

7 files changed

+205
-2
lines changed

7 files changed

+205
-2
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.idea/*
2+
*.log
3+
*.bak
4+
*.DS_Store
5+
*.orig
6+
*Thumbs.db
7+
vendor/
8+
composer.lock

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Changelog
2+
=========
3+
4+
## Unreleased
5+
6+
Initial release.

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Pixel & Tonic, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# commerce-omnipay
2-
Omnipay support for Craft Commerce
1+
Omnipay payment gateway support for Craft Commerce
2+
=======================

composer.json

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"name": "craftcms/commerce-omnipay",
3+
"description": "Omnipay integration for Craft Commerce",
4+
"version": "1.0.0",
5+
"keywords": [
6+
"commerce",
7+
"craftcms",
8+
"omnipay",
9+
"yii2"
10+
],
11+
"license": "MIT",
12+
"authors": [
13+
{
14+
"name": "Pixel & Tonic",
15+
"homepage": "https://pixelandtonic.com/"
16+
}
17+
],
18+
"support": {
19+
"email": "[email protected]",
20+
"issues": "https://github.com/craftcms/commerce-omnipay/issues?state=open",
21+
"source": "https://github.com/craftcms/commerce-omnipay",
22+
"docs": "https://github.com/craftcms/commerce-omnipay",
23+
"rss": "https://github.com/craftcms/commerce-omnipay/commits/master.atom"
24+
},
25+
"require": {
26+
"craftcms/commerce": "*",
27+
"omnipay/common": "~2.3"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"craft\\commerce\\omnipay\\": "src/"
32+
}
33+
},
34+
"repositories": [
35+
{
36+
"type": "composer",
37+
"url": "https://asset-packagist.org"
38+
}
39+
],
40+
"extra": {
41+
"name": "Omnipay",
42+
"handle": "commerce-omnipay",
43+
"changelogUrl": "https://raw.githubusercontent.com/craftcms/commerce-omnipay/master/CHANGELOG.md",
44+
"downloadUrl": "https://github.com/craftcms/commerce-omnipay/archive/master.zip"
45+
}
46+
}

src/base/CreditCardGateway.php

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace craft\commerce\omnipay\base;
4+
5+
use craft\commerce\base\CreditCardGatewayTrait;
6+
use craft\commerce\models\payments\BasePaymentForm;
7+
use craft\commerce\models\payments\CreditCardPaymentForm;
8+
use Omnipay\Common\CreditCard;
9+
use Omnipay\Common\Message\AbstractRequest;
10+
11+
/**
12+
* This is an abstract class to be used by credit card gateways
13+
*
14+
* @author Pixel & Tonic, Inc. <[email protected]>
15+
* @copyright Copyright (c) 2017, Pixel & Tonic, Inc.
16+
* @license https://craftcommerce.com/license Craft Commerce License Agreement
17+
* @see https://craftcommerce.com
18+
* @package craft.commerce
19+
* @since 2.0
20+
*/
21+
abstract class CreditCardGateway extends Gateway
22+
{
23+
use CreditCardGatewayTrait;
24+
25+
/**
26+
* @inheritdoc
27+
*/
28+
public function populateCard($card, CreditCardPaymentForm $paymentForm)
29+
{
30+
if (!$card instanceof CreditCard) {
31+
return;
32+
}
33+
34+
$card->setFirstName($paymentForm->firstName);
35+
$card->setLastName($paymentForm->lastName);
36+
$card->setNumber($paymentForm->number);
37+
$card->setExpiryMonth($paymentForm->month);
38+
$card->setExpiryYear($paymentForm->year);
39+
$card->setCvv($paymentForm->cvv);
40+
}
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
public function populateRequest(AbstractRequest $request, BasePaymentForm $paymentForm)
46+
{
47+
if ($paymentForm->hasProperty('token')) {
48+
$request->setToken($paymentForm->token);
49+
}
50+
}
51+
}

src/base/Gateway.php

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace craft\commerce\omnipay\base;
4+
5+
use craft\commerce\base\Gateway as BaseGateway;
6+
use craft\commerce\elements\Order;
7+
use Omnipay\Common\AbstractGateway;
8+
use Omnipay\Common\ItemBag;
9+
use Omnipay\Omnipay;
10+
11+
/**
12+
* Class Payment Method Model
13+
*
14+
* @package Craft
15+
16+
* @author Pixel & Tonic, Inc. <[email protected]>
17+
* @copyright Copyright (c) 2017, Pixel & Tonic, Inc.
18+
* @license https://craftcommerce.com/license Craft Commerce License Agreement
19+
* @see https://craftcommerce.com
20+
* @package craft.commerce
21+
* @since 2.0
22+
*/
23+
abstract class Gateway extends BaseGateway
24+
{
25+
/**
26+
* @var AbstractGateway
27+
*/
28+
private $_gateway;
29+
30+
/**
31+
* @param Order $order
32+
*
33+
* @return ItemBag
34+
*/
35+
public function createItemBag(Order $order): ItemBag
36+
{
37+
if (!$this->canSendCartInfo) {
38+
return null;
39+
}
40+
41+
$items = $this->generateItemList($order);
42+
$itemBagClassName = $this->getItemBagClassName();
43+
44+
return new $itemBagClassName($items);
45+
}
46+
47+
48+
// Protected Methods
49+
// =========================================================================
50+
51+
/**
52+
* @return AbstractGateway
53+
*/
54+
protected function gateway(): AbstractGateway
55+
{
56+
if ($this->_gateway !== null) {
57+
return $this->_gateway;
58+
}
59+
60+
return $this->_gateway = $this->createGateway();
61+
}
62+
63+
/**
64+
* Return the class name used for item bags by this gateway.
65+
*
66+
* @return string
67+
*/
68+
protected function getItemBagClassName(): string {
69+
return ItemBag::class;
70+
}
71+
}

0 commit comments

Comments
 (0)