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

Send client_reference_id with PurchaseRequest #220

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/Message/Checkout/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,37 @@ public function getClientReferenceId()
return $this->getParameter('client_reference_id');
}

/**
* Set the customer_creation parameter
*
* @param string $value
*
* @return \Omnipay\Common\Message\AbstractRequest|PurchaseRequest
*/
public function setCustomerCreation($value)
{
return $this->setParameter('customer_creation', $value);
}

/**
* Get the customer_creation parameter
*
* @return string
*/
public function getCustomerCreation()
{
return $this->getParameter('customer_creation');
}

public function getData()
{
$data = array(
'client_reference_id' => $this->getClientReferenceId(),
'success_url' => $this->getSuccessUrl(),
'cancel_url' => $this->getCancelUrl(),
'payment_method_types' => $this->getPaymentMethodTypes(),
'mode' => $this->getMode(),
'customer_creation' => $this->getCustomerCreation(),
'line_items' => $this->getLineItems()
);

Expand Down
45 changes: 43 additions & 2 deletions src/Message/PaymentIntents/AuthorizeRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,42 @@ public function getOffSession()
return $this->getParameter('off_session');
}

/**
* @return mixed
*/
public function getConfirmationMethod()
{
return $this->getParameter('confirmation_method');
}

/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setConfirmationMethod($value)
{
return $this->setParameter('confirmation_method', $value);
}

/**
* @return mixed
*/
public function getCaptureMethod()
{
return $this->getParameter('capture_method');
}

/**
* @param string $value
*
* @return AbstractRequest provides a fluent interface.
*/
public function setCaptureMethod($value)
{
return $this->setParameter('capture_method', $value);
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -392,8 +428,13 @@ public function getData()

$data['off_session'] = $this->getOffSession() ? 'true' : 'false';

$data['confirmation_method'] = 'manual';
$data['capture_method'] = 'manual';
if ($this->getConfirmationMethod()) {
$data['confirmation_method'] = $this->getConfirmationMethod();
}

if ($this->getCaptureMethod()) {
$data['capture_method'] = $this->getCaptureMethod();
}

$data['confirm'] = $this->getConfirm() ? 'true' : 'false';

Expand Down
2 changes: 1 addition & 1 deletion src/Message/PaymentIntents/CreatePaymentMethodRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function getBillingDetails()
'country' => $data['address_country'],
'line1' => $data['address_line1'],
'line2' => $data['address_line2'],
'postal_code' => $data['address_zip'],
'postal_code' => $data['address_zip'] ?? null,
'state' => $data['address_state'],
]),
]);
Expand Down
31 changes: 31 additions & 0 deletions tests/Message/Checkout/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Omnipay\Stripe\Message\Checkout;

use Omnipay\Tests\TestCase;

class PurchaseRequestTest extends TestCase
{
/**
* @var PurchaseRequest
*/
protected $request;

public function setUp()
{
$this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest());
$this->request->initialize(
array(
'client_reference_id' => 'cart_id_123'
)
);
}

public function testGetData()
{
$data = $this->request->getData();

$this->assertSame('cart_id_123', $data['client_reference_id']);
}

}