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

Paypal_Express Gateway does not send Items to paypal for descriptions #238

Open
EEKimS opened this issue Jan 17, 2023 · 0 comments
Open

Comments

@EEKimS
Copy link

EEKimS commented Jan 17, 2023

I am pulling my hair out on this issue, after a lot of digging it looks like i need to send an array of items through the purchase and completePurchase functions. I am using Silverstripe Omnipay and SilverShop to handle the shop.

$request = $gateway->purchase($params)->setItems(array(
    array('name' => 'item1', 'quantity' => 2, 'price' => '10.00', 'description' => 'some description'),
    array('name' => 'item2', 'quantity' => 1, 'price' => '50.00',  'description' => 'some description')
))->send();

Here is a list of articles i used to sort of help me find my 'solution'

thephpleague/omnipay#154
https://stackoverflow.com/questions/25361190/list-multiple-items-through-paypal-express-checkout-using-omnipay-laravel-4
https://stackoverflow.com/questions/29688023/how-to-send-description-of-products-to-paypal-express-omnipay

Through a lot of digging i was able to find the file silverstripe-omnipay\src\Service\PurchaseService.php that has several extension hooks that look like they should do this using the method hooks onBeforePurchase, onAfterPurchase, onBeforeCompletePurchase, and onAfterCompletePurchase

I set up some really rough methods in an extension that create an array of the items, and adds it onto the requests, a bit like this:

<?php

namespace SilverStripe\Omnipay\Service;

use SilverStripe\Omnipay\Exception\InvalidStateException;
use SilverStripe\Omnipay\Exception\InvalidConfigurationException;
use SilverStripe\Omnipay\Helper\ErrorHandling;
use SilverStripe\Omnipay\Model\Message\AwaitingPurchaseResponse;
use SilverStripe\Omnipay\Model\Message\CompletePurchaseError;
use SilverStripe\Omnipay\Model\Message\CompletePurchaseRequest;
use SilverStripe\Omnipay\Model\Message\PurchasedResponse;
use SilverStripe\Omnipay\Model\Message\PurchaseError;
use SilverStripe\Omnipay\Model\Message\PurchaseRedirectResponse;
use SilverStripe\Omnipay\Model\Message\PurchaseRequest;

class PurchaseService extends PaymentService
{
    public function onAfterPurchase($request){
        $bag = array();
        // stuff to build the array - it's really ugly so i haven't included it here
        // I can build and return the array, but it doesn't seem to make it into the requests.
        $request->setItems($bag);
    }
}

This is implemented through the Injector class to extend the original.

Basically i have this function duplicated in onAfterPurchase() and onAfterCompletePurchase();

However, this information never seems to make it through the requests to actually send to paypal, and is an empty PayPalItemBag object in the response.

Please help, after days of digging through code to get this far i am at my wits end.

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

1 participant