Skip to content

Commit

Permalink
Merge pull request schmittjoh#68 from ruudk/notify_url
Browse files Browse the repository at this point in the history
Allow specifying dynamic return_url for IPN
  • Loading branch information
schmittjoh committed Jul 23, 2014
2 parents 5c58d99 + b91c12d commit ed66e95
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public function getConfigTree()
->scalarNode('signature')->isRequired()->cannotBeEmpty()->end()
->scalarNode('return_url')->defaultNull()->end()
->scalarNode('cancel_url')->defaultNull()->end()
->scalarNode('notify_url')->defaultNull()->end()
->booleanNode('debug')->defaultValue('%kernel.debug%')->end()
->end()
->end()
->buildTree();
}
}
}
3 changes: 2 additions & 1 deletion DependencyInjection/JMSPaymentPaypalExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('payment.paypal.signature', $config['signature']);
$container->setParameter('payment.paypal.express_checkout.return_url', $config['return_url']);
$container->setParameter('payment.paypal.express_checkout.cancel_url', $config['cancel_url']);
$container->setParameter('payment.paypal.express_checkout.notify_url', $config['notify_url']);
$container->setParameter('payment.paypal.debug', $config['debug']);
}
}
}
31 changes: 28 additions & 3 deletions Plugin/ExpressCheckoutPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class ExpressCheckoutPlugin extends AbstractPlugin
*/
protected $cancelUrl;

/**
* @var string
*/
protected $notifyUrl;

/**
* @var \JMS\Payment\PaypalBundle\Client\Client
*/
Expand All @@ -51,12 +56,14 @@ class ExpressCheckoutPlugin extends AbstractPlugin
* @param string $returnUrl
* @param string $cancelUrl
* @param \JMS\Payment\PaypalBundle\Client\Client $client
* @param string $notifyUrl
*/
public function __construct($returnUrl, $cancelUrl, Client $client)
public function __construct($returnUrl, $cancelUrl, Client $client, $notifyUrl = null)
{
$this->client = $client;
$this->returnUrl = $returnUrl;
$this->cancelUrl = $cancelUrl;
$this->notifyUrl = $notifyUrl;
}

public function approve(FinancialTransactionInterface $transaction, $retry)
Expand Down Expand Up @@ -188,12 +195,20 @@ protected function createCheckoutBillingAgreement(FinancialTransactionInterface
// complete the transaction
$data->set('paypal_payer_id', $details->body->get('PAYERID'));

$optionalParameters = array(
'PAYMENTREQUEST_0_CURRENCYCODE' => $transaction->getPayment()->getPaymentInstruction()->getCurrency(),
);

if (null !== $notifyUrl = $this->getNotifyUrl($data)) {
$optionalParameters['PAYMENTREQUEST_0_NOTIFYURL'] = $notifyUrl;
}

$response = $this->client->requestDoExpressCheckoutPayment(
$data->get('express_checkout_token'),
$transaction->getRequestedAmount(),
$paymentAction,
$details->body->get('PAYERID'),
array('PAYMENTREQUEST_0_CURRENCYCODE' => $transaction->getPayment()->getPaymentInstruction()->getCurrency())
$optionalParameters
);
$this->throwUnlessSuccessResponse($response, $transaction);

Expand Down Expand Up @@ -303,4 +318,14 @@ protected function getCancelUrl(ExtendedDataInterface $data)

throw new \RuntimeException('You must configure a cancel url.');
}
}

protected function getNotifyUrl(ExtendedDataInterface $data)
{
if ($data->has('notify_url')) {
return $data->get('notify_url');
}
else if (0 !== strlen($this->notifyUrl)) {
return $this->notifyUrl;
}
}
}
2 changes: 2 additions & 0 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<parameter key="payment.plugin.paypal_express_checkout.class">JMS\Payment\PaypalBundle\Plugin\ExpressCheckoutPlugin</parameter>
<parameter key="payment.paypal.express_checkout.return_url"></parameter>
<parameter key="payment.paypal.express_checkout.cancel_url"></parameter>
<parameter key="payment.paypal.express_checkout.notify_url"></parameter>

<parameter key="payment.paypal.authentication_strategy.token.class">JMS\Payment\PaypalBundle\Client\Authentication\TokenAuthenticationStrategy</parameter>
<parameter key="payment.paypal.username"></parameter>
Expand All @@ -32,6 +33,7 @@
<argument>%payment.paypal.express_checkout.return_url%</argument>
<argument>%payment.paypal.express_checkout.cancel_url%</argument>
<argument type="service" id="payment.paypal.client" />
<argument>%payment.paypal.express_checkout.notify_url%</argument>
<tag name="payment.plugin" />
</service>

Expand Down

0 comments on commit ed66e95

Please sign in to comment.