-
Notifications
You must be signed in to change notification settings - Fork 176
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 #142 from flo-sch/in-context-checkout
[In-Context] Create a new PayPal Express In-Context gateway extending…
- Loading branch information
Showing
10 changed files
with
584 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayPal; | ||
|
||
/** | ||
* PayPal Express In-Context Class | ||
*/ | ||
class ExpressInContextGateway extends ExpressGateway | ||
{ | ||
public function getName() | ||
{ | ||
return 'PayPal Express In-Context'; | ||
} | ||
|
||
public function authorize(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\PayPal\Message\ExpressInContextAuthorizeRequest', $parameters); | ||
} | ||
|
||
public function order(array $parameters = array()) | ||
{ | ||
return $this->createRequest('\Omnipay\PayPal\Message\ExpressInContextOrderRequest', $parameters); | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayPal\Message; | ||
|
||
/** | ||
* PayPal Express In-Context Authorize Request | ||
*/ | ||
class ExpressInContextAuthorizeRequest extends ExpressAuthorizeRequest | ||
{ | ||
protected function createResponse($data) | ||
{ | ||
return $this->response = new ExpressInContextAuthorizeResponse($this, $data); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayPal\Message; | ||
|
||
/** | ||
* PayPal Express In-Context Authorize Response | ||
*/ | ||
class ExpressInContextAuthorizeResponse extends ExpressAuthorizeResponse | ||
{ | ||
protected $liveCheckoutEndpoint = 'https://www.paypal.com/checkoutnow'; | ||
protected $testCheckoutEndpoint = 'https://www.sandbox.paypal.com/checkoutnow'; | ||
|
||
protected function getRedirectQueryParameters() | ||
{ | ||
return array( | ||
'useraction' => 'commit', | ||
'token' => $this->getTransactionReference(), | ||
); | ||
} | ||
} |
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,17 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayPal\Message; | ||
|
||
/** | ||
* PayPal Express In-Context Order Request | ||
*/ | ||
class ExpressInContextOrderRequest extends ExpressInContextAuthorizeRequest | ||
{ | ||
public function getData() | ||
{ | ||
$data = parent::getData(); | ||
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Order'; | ||
|
||
return $data; | ||
} | ||
} |
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,78 @@ | ||
<?php | ||
|
||
namespace Omnipay\PayPal; | ||
|
||
use Omnipay\Tests\GatewayTestCase; | ||
|
||
class ExpressInContextGatewayTest extends GatewayTestCase | ||
{ | ||
/** | ||
* @var \Omnipay\PayPal\ExpressInContextGateway | ||
*/ | ||
protected $gateway; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $options; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $voidOptions; | ||
|
||
public function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->gateway = new ExpressInContextGateway($this->getHttpClient(), $this->getHttpRequest()); | ||
|
||
$this->options = array( | ||
'amount' => '10.00', | ||
'returnUrl' => 'https://www.example.com/return', | ||
'cancelUrl' => 'https://www.example.com/cancel', | ||
); | ||
$this->voidOptions = array( | ||
'transactionReference' => 'ASDFASDFASDF', | ||
); | ||
} | ||
|
||
public function testAuthorizeSuccess() | ||
{ | ||
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); | ||
|
||
$response = $this->gateway->authorize($this->options)->send(); | ||
|
||
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response); | ||
$this->assertFalse($response->isPending()); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertTrue($response->isRedirect()); | ||
$this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); | ||
} | ||
|
||
public function testPurchaseSuccess() | ||
{ | ||
$this->setMockHttpResponse('ExpressPurchaseSuccess.txt'); | ||
|
||
$response = $this->gateway->purchase($this->options)->send(); | ||
|
||
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response); | ||
$this->assertFalse($response->isPending()); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertTrue($response->isRedirect()); | ||
$this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); | ||
} | ||
|
||
public function testOrderSuccess() | ||
{ | ||
$this->setMockHttpResponse('ExpressOrderSuccess.txt'); | ||
|
||
$response = $this->gateway->order($this->options)->send(); | ||
|
||
$this->assertInstanceOf('\Omnipay\PayPal\Message\ExpressInContextAuthorizeResponse', $response); | ||
$this->assertFalse($response->isPending()); | ||
$this->assertFalse($response->isSuccessful()); | ||
$this->assertTrue($response->isRedirect()); | ||
$this->assertEquals('https://www.paypal.com/checkoutnow?useraction=commit&token=EC-42721413K79637829', $response->getRedirectUrl()); | ||
} | ||
} |
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.