Skip to content

Commit a07f70f

Browse files
authored
Merge pull request #4578 from magento-honey-badgers/badgers-pr
[honey] MC-17120: PayPal :: Additional Payments Support
2 parents cac46e0 + 8bf85ec commit a07f70f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1732
-261
lines changed

app/code/Magento/AuthorizenetGraphQl/Model/AuthorizenetDataProvider.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use Magento\Framework\Stdlib\ArrayManager;
1212

1313
/**
14-
* DataProvider Model for Authorizenet
14+
* SetPaymentMethod additional data provider model for Authorizenet payment method
1515
*/
1616
class AuthorizenetDataProvider implements AdditionalDataProviderInterface
1717
{
@@ -23,7 +23,6 @@ class AuthorizenetDataProvider implements AdditionalDataProviderInterface
2323
private $arrayManager;
2424

2525
/**
26-
* AuthorizenetDataProvider constructor.
2726
* @param ArrayManager $arrayManager
2827
*/
2928
public function __construct(
@@ -42,19 +41,19 @@ public function getData(array $data): array
4241
{
4342
$additionalData = $this->arrayManager->get(static::PATH_ADDITIONAL_DATA, $data) ?? [];
4443
foreach ($additionalData as $key => $value) {
45-
$additionalData[$this->snakeCaseToCamelCase($key)] = $value;
44+
$additionalData[$this->convertSnakeCaseToCamelCase($key)] = $value;
4645
unset($additionalData[$key]);
4746
}
4847
return $additionalData;
4948
}
5049

5150
/**
52-
* Converts an input string from snake_case to camelCase.
51+
* Convert an input string from snake_case to camelCase.
5352
*
5453
* @param string $input
5554
* @return string
5655
*/
57-
private function snakeCaseToCamelCase($input)
56+
private function convertSnakeCaseToCamelCase($input): string
5857
{
5958
return lcfirst(str_replace('_', '', ucwords($input, '_')));
6059
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model;
9+
10+
use \Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface;
11+
12+
/**
13+
* Resolver for Media Gallery type.
14+
*/
15+
class MediaGalleryTypeResolver implements TypeResolverInterface
16+
{
17+
/**
18+
* @inheritdoc
19+
*
20+
* @param array $data
21+
* @return string
22+
*/
23+
public function resolveType(array $data) : string
24+
{
25+
// resolve type based on the data
26+
if (isset($data['media_type']) && $data['media_type'] == 'image') {
27+
return 'ProductImage';
28+
}
29+
if (isset($data['media_type']) && $data['media_type'] == 'external-video') {
30+
return 'ProductVideo';
31+
}
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Product;
9+
10+
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
12+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13+
use Magento\Catalog\Api\Data\ProductInterface;
14+
use Magento\Framework\GraphQl\Config\Element\Field;
15+
use Magento\Framework\GraphQl\Query\ResolverInterface;
16+
17+
/**
18+
* @inheritdoc
19+
*
20+
* Format a product's media gallery information to conform to GraphQL schema representation
21+
*/
22+
class MediaGallery implements ResolverInterface
23+
{
24+
/**
25+
* @inheritdoc
26+
*
27+
* Format product's media gallery entry data to conform to GraphQL schema
28+
*
29+
* @param \Magento\Framework\GraphQl\Config\Element\Field $field
30+
* @param ContextInterface $context
31+
* @param ResolveInfo $info
32+
* @param array|null $value
33+
* @param array|null $args
34+
* @throws \Exception
35+
* @return array
36+
*/
37+
public function resolve(
38+
Field $field,
39+
$context,
40+
ResolveInfo $info,
41+
array $value = null,
42+
array $args = null
43+
) {
44+
if (!isset($value['model'])) {
45+
throw new LocalizedException(__('"model" value should be specified'));
46+
}
47+
48+
/** @var ProductInterface $product */
49+
$product = $value['model'];
50+
51+
$mediaGalleryEntries = [];
52+
foreach ($product->getMediaGalleryEntries() ?? [] as $key => $entry) {
53+
$mediaGalleryEntries[$key] = $entry->getData();
54+
$mediaGalleryEntries[$key]['model'] = $product;
55+
if ($entry->getExtensionAttributes() && $entry->getExtensionAttributes()->getVideoContent()) {
56+
$mediaGalleryEntries[$key]['video_content']
57+
= $entry->getExtensionAttributes()->getVideoContent()->getData();
58+
}
59+
}
60+
return $mediaGalleryEntries;
61+
}
62+
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage/Label.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGallery/Label.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductImage;
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Product\MediaGallery;
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\ResourceModel\Product as ProductResourceModel;
1212
use Magento\Framework\Exception\LocalizedException;
1313
use Magento\Framework\GraphQl\Config\Element\Field;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16+
use Magento\Store\Api\Data\StoreInterface;
1617

1718
/**
18-
* Returns product's image label
19+
* Return media label
1920
*/
2021
class Label implements ResolverInterface
2122
{
@@ -43,8 +44,9 @@ public function resolve(
4344
array $value = null,
4445
array $args = null
4546
) {
46-
if (!isset($value['image_type'])) {
47-
throw new LocalizedException(__('"image_type" value should be specified'));
47+
48+
if (isset($value['label'])) {
49+
return $value['label'];
4850
}
4951

5052
if (!isset($value['model'])) {
@@ -53,18 +55,16 @@ public function resolve(
5355

5456
/** @var Product $product */
5557
$product = $value['model'];
56-
$imageType = $value['image_type'];
57-
$imagePath = $product->getData($imageType);
5858
$productId = (int)$product->getEntityId();
59-
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
60-
61-
// null if image is not set
62-
if (null === $imagePath) {
59+
/** @var StoreInterface $store */
60+
$store = $context->getExtensionAttributes()->getStore();
61+
$storeId = (int)$store->getId();
62+
if (!isset($value['image_type'])) {
6363
return $this->getAttributeValue($productId, 'name', $storeId);
6464
}
65-
65+
$imageType = $value['image_type'];
6666
$imageLabel = $this->getAttributeValue($productId, $imageType . '_label', $storeId);
67-
if (null === $imageLabel) {
67+
if ($imageLabel == null) {
6868
$imageLabel = $this->getAttributeValue($productId, 'name', $storeId);
6969
}
7070

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage/Url.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGallery/Url.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\CatalogGraphQl\Model\Resolver\Product\ProductImage;
8+
namespace Magento\CatalogGraphQl\Model\Resolver\Product\MediaGallery;
99

1010
use Magento\Catalog\Model\Product;
1111
use Magento\Catalog\Model\Product\ImageFactory;
@@ -16,7 +16,7 @@
1616
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1717

1818
/**
19-
* Returns product's image url
19+
* Returns media url
2020
*/
2121
class Url implements ResolverInterface
2222
{
@@ -51,7 +51,7 @@ public function resolve(
5151
array $value = null,
5252
array $args = null
5353
) {
54-
if (!isset($value['image_type'])) {
54+
if (!isset($value['image_type']) && !isset($value['file'])) {
5555
throw new LocalizedException(__('"image_type" value should be specified'));
5656
}
5757

@@ -61,9 +61,17 @@ public function resolve(
6161

6262
/** @var Product $product */
6363
$product = $value['model'];
64-
$imagePath = $product->getData($value['image_type']);
65-
66-
return $this->getImageUrl($value['image_type'], $imagePath);
64+
if (isset($value['image_type'])) {
65+
$imagePath = $product->getData($value['image_type']);
66+
return $this->getImageUrl($value['image_type'], $imagePath);
67+
}
68+
if (isset($value['file'])) {
69+
$image = $this->productImageFactory->create();
70+
$image->setDestinationSubdir('image')->setBaseFile($value['file']);
71+
$imageUrl = $image->getUrl();
72+
return $imageUrl;
73+
}
74+
return [];
6775
}
6876

6977
/**

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/MediaGalleryEntries.php

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* @inheritdoc
1919
*
2020
* Format a product's media gallery information to conform to GraphQL schema representation
21+
* @deprecated
2122
*/
2223
class MediaGalleryEntries implements ResolverInterface
2324
{

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Product.php

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ public function getList(
8989
if (in_array('media_gallery_entries', $attributes)) {
9090
$collection->addMediaGalleryData();
9191
}
92+
if (in_array('media_gallery', $attributes)) {
93+
$collection->addMediaGalleryData();
94+
}
9295
if (in_array('options', $attributes)) {
9396
$collection->addOptionsToResult();
9497
}

app/code/Magento/CatalogGraphQl/etc/schema.graphqls

+12-4
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ interface ProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\
9292
type_id: String @doc(description: "One of simple, virtual, bundle, downloadable, grouped, or configurable.")
9393
websites: [Website] @doc(description: "An array of websites in which the product is available.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Websites")
9494
product_links: [ProductLinksInterface] @doc(description: "An array of ProductLinks objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductLinks")
95-
media_gallery_entries: [MediaGalleryEntry] @doc(description: "An array of MediaGalleryEntry objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGalleryEntries")
95+
media_gallery_entries: [MediaGalleryEntry] @deprecated(reason: "Use product's `media_gallery` instead") @doc(description: "An array of MediaGalleryEntry objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGalleryEntries")
9696
tier_prices: [ProductTierPrices] @doc(description: "An array of ProductTierPrices objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\TierPrices")
9797
price: ProductPrices @doc(description: "A ProductPrices object, indicating the price of an item.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Price")
9898
gift_message_available: String @doc(description: "Indicates whether a gift message is available.")
9999
manufacturer: Int @doc(description: "A number representing the product's manufacturer.")
100100
categories: [CategoryInterface] @doc(description: "The categories assigned to a product.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Categories") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Category\\CategoriesIdentity")
101101
canonical_url: String @doc(description: "Canonical URL.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\CanonicalUrl")
102+
media_gallery: [MediaGalleryInterface] @doc(description: "An array of Media Gallery objects.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGallery")
102103
}
103104

104105
interface PhysicalProductInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\ProductInterfaceTypeResolverComposite") @doc(description: "PhysicalProductInterface contains attributes specific to tangible products.") {
@@ -184,9 +185,12 @@ type CustomizableFileValue @doc(description: "CustomizableFileValue defines the
184185
image_size_y: Int @doc(description: "The maximum height of an image.")
185186
}
186187

187-
type ProductImage @doc(description: "Product image information. Contains image relative path, URL and label.") {
188-
url: String @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage\\Url")
189-
label: String @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\ProductImage\\Label")
188+
interface MediaGalleryInterface @doc(description: "Contains basic information about a product image or video.") @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\MediaGalleryTypeResolver") {
189+
url: String @doc(description: "The URL of the product image or video.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGallery\\Url")
190+
label: String @doc(description: "The label of the product image or video.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\MediaGallery\\Label")
191+
}
192+
193+
type ProductImage implements MediaGalleryInterface @doc(description: "Product image information. Contains the image URL and label.") {
190194
}
191195

192196
interface CustomizableOptionInterface @typeResolver(class: "Magento\\CatalogGraphQl\\Model\\CustomizableOptionTypeResolver") @doc(description: "The CustomizableOptionInterface contains basic information about a customizable option. It can be implemented by several types of configurable options.") {
@@ -413,3 +417,7 @@ type StoreConfig @doc(description: "The type contains information about a store
413417
list_per_page : Int @doc(description: "Products per Page on List Default Value.")
414418
catalog_default_sort_by : String @doc(description: "Default Sort By.")
415419
}
420+
421+
type ProductVideo @doc(description: "Contains information about a product video.") implements MediaGalleryInterface {
422+
video_content: ProductMediaGalleryEntriesVideoContent @doc(description: "Contains a ProductMediaGalleryEntriesVideoContent object.")
423+
}

app/code/Magento/Paypal/Model/Hostedpro.php

+10-4
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public function __construct(
140140

141141
/**
142142
* Return available CC types for gateway based on merchant country.
143+
*
143144
* We do not have to check the availability of card types.
144145
*
145146
* @return true
@@ -150,8 +151,9 @@ public function getAllowedCcTypes()
150151
}
151152

152153
/**
153-
* Return merchant country code from config,
154-
* use default country if it not specified in General settings
154+
* Return merchant country code from config
155+
*
156+
* Use default country if it not specified in General settings
155157
*
156158
* @return string
157159
*/
@@ -274,7 +276,9 @@ protected function buildBasicRequest()
274276
*/
275277
public function getReturnUrl($storeId = null)
276278
{
277-
return $this->getUrl('paypal/hostedpro/return', $storeId);
279+
$payment = $this->getInfoInstance();
280+
$urlRoute = $payment->getAdditionalInformation('return_url') ?? 'paypal/hostedpro/return';
281+
return $this->getUrl($urlRoute, $storeId);
278282
}
279283

280284
/**
@@ -296,7 +300,9 @@ public function getNotifyUrl($storeId = null)
296300
*/
297301
public function getCancelUrl($storeId = null)
298302
{
299-
return $this->getUrl('paypal/hostedpro/cancel', $storeId);
303+
$payment = $this->getInfoInstance();
304+
$urlRoute = $payment->getAdditionalInformation('cancel_url') ?? 'paypal/hostedpro/cancel';
305+
return $this->getUrl($urlRoute, $storeId);
300306
}
301307

302308
/**

app/code/Magento/Paypal/Model/Payflowlink.php

-27
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,6 @@ protected function _buildTokenRequest(\Magento\Sales\Model\Order\Payment $paymen
425425
$request->setCreatesecuretoken('Y')
426426
->setSecuretokenid($this->mathRandom->getUniqueHash())
427427
->setTrxtype($this->_getTrxTokenType());
428-
$request = $this->updateRequestReturnUrls($request, $payment);
429428

430429
$order = $payment->getOrder();
431430
$request->setAmt(sprintf('%.2F', $order->getBaseTotalDue()))
@@ -601,30 +600,4 @@ protected function _getCallbackUrl($actionName)
601600

602601
return $websiteUrl . 'paypal/' . $this->_callbackController . '/' . $actionName;
603602
}
604-
605-
/**
606-
* Update the redirect urls on the request if they are set on the payment
607-
*
608-
* @param \Magento\Paypal\Model\Payflow\Request $request
609-
* @param \Magento\Sales\Model\Order\Payment $payment
610-
* @return \Magento\Paypal\Model\Payflow\Request
611-
*/
612-
private function updateRequestReturnUrls(
613-
\Magento\Paypal\Model\Payflow\Request $request,
614-
\Magento\Sales\Model\Order\Payment $payment
615-
): \Magento\Paypal\Model\Payflow\Request {
616-
$paymentData = $payment->getAdditionalInformation();
617-
618-
if (!empty($paymentData['cancel_url'])) {
619-
$request->setCancelurl($paymentData['cancel_url']);
620-
}
621-
if (!empty($paymentData['return_url'])) {
622-
$request->setReturnurl($paymentData['return_url']);
623-
}
624-
if (!empty($paymentData['error_url'])) {
625-
$request->setErrorurl($paymentData['error_url']);
626-
}
627-
628-
return $request;
629-
}
630603
}

0 commit comments

Comments
 (0)