Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@
/vendor
composer.lock
composer.phar

*.env
42 changes: 42 additions & 0 deletions lib/Shift4/Request/PaymentMethodRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,46 @@ public function applePay($applePay)
{
return $this->set('applePay', $applePay);
}

/**
* @return \Shift4\Request\PaymentMethodRequestGooglePay
*/
public function getGooglePay()
{
return $this->getObject('googlePay', '\Shift4\Request\PaymentMethodRequestGooglePay');
}

/**
* @param \Shift4\Request\PaymentMethodRequestGooglePay $googlePay
*/
public function googlePay($googlePay)
{
return $this->set('googlePay', $googlePay);
}

/**
* @return \Shift4\Request\ThreeDSecure
*/
public function getThreeDSecure()
{
return $this->getObject('threeDSecure', '\Shift4\Request\ThreeDSecure');
}

/**
* @param \Shift4\Request\ThreeDSecure $threeDSecure
*/
public function threeDSecure($threeDSecure)
{
return $this->set('threeDSecure', $threeDSecure);
}

public function getSource()
{
return $this->get('source');
}

public function source($source)
{
return $this->set('source', $source);
}
}
21 changes: 21 additions & 0 deletions lib/Shift4/Request/PaymentMethodRequestGooglePay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Shift4\Request;

class PaymentMethodRequestGooglePay extends AbstractRequest
{

public function getToken()
{
return $this->get('token');
}

/**
* @param string $token token received from apple pay
* @return PaymentMethodRequestGooglePay
*/
public function token($token)
{
return $this->set('token', $token);
}
}
27 changes: 27 additions & 0 deletions lib/Shift4/Request/ThreeDSecure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Shift4\Request;

class ThreeDSecure extends AbstractRequest
{

public function getCurrency()
{
return $this->get('currency');
}

public function currency($currency)
{
return $this->set('currency', $currency);
}

public function getAmount()
{
return $this->get('amount');
}

public function amount($amount)
{
return $this->set('amount', $amount);
}
}
30 changes: 30 additions & 0 deletions lib/Shift4/Response/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,34 @@ public function getApplePay()
{
return $this->getObject('applePay', '\Shift4\Response\PaymentMethodApplePay');
}

/**
* @return \Shift4\Response\PaymentMethodGooglePay
*/
public function getGooglePay()
{
return $this->getObject('googlePay', '\Shift4\Response\PaymentMethodGooglePay');
}

/**
* @return \Shift4\Response\ThreeDSecure
*/
public function getThreeDSecure()
{
return $this->getObject('threeDSecure', '\Shift4\Response\ThreeDSecure');
}

public function getSource()
{
return $this->get('source');
}

/**
* @return \Shift4\Response\PaymentMethodFlowResponse
*/
public function getFlow()
{
return $this->getObject('flow', '\Shift4\Response\PaymentMethodFlowResponse');
}

}
11 changes: 11 additions & 0 deletions lib/Shift4/Response/PaymentMethodFlowResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Shift4\Response;

class PaymentMethodFlowResponse extends AbstractResponse
{
public function getNextAction()
{
return $this->get('nextAction');
}
}
36 changes: 36 additions & 0 deletions lib/Shift4/Response/PaymentMethodGooglePay.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Shift4\Response;

class PaymentMethodGooglePay extends AbstractResponse
{
public function getCardBrand()
{
return $this->get('cardBrand');
}

public function getCardType()
{
return $this->get('cardType');
}

public function getFirst6()
{
return $this->get('first6');
}

public function getLast4()
{
return $this->get('last4');
}

public function getAmount()
{
return $this->get('amount');
}

public function getCurrency()
{
return $this->get('currency');
}
}
17 changes: 17 additions & 0 deletions lib/Shift4/Response/ThreeDSecure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Shift4\Response;

class ThreeDSecure extends AbstractResponse
{

public function getCurrency()
{
return $this->get('currency');
}

public function getAmount()
{
return $this->get('amount');
}
}
30 changes: 30 additions & 0 deletions tests/ChargeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,36 @@ function testDispute()
self::assertEquals(false, $charge->getDispute()->getAcceptedAsLost());
}

public function testCreateChargeForGooglePayPanOnly()
{
// given
$request = Data::googlePayPaymentMethodPanOnly();
$response = $this->gateway->createPaymentMethod($request);

// then
Assert::assertEquals($request->getType(), $response->getType());
Assert::assertNotNull($response->getGooglePay());
Assert::assertNotNull($response->getFlow());
Assert::assertNotNull($response->getFlow()->getNextAction());
}

public function testCreateChargeForGoogle3ds()
{
// given
$source = $this->gateway->createPaymentMethod(Data::googlePayPaymentMethod3ds());
$request = Data::threeDSecurePaymentMethod($source, 'USD', 400);
$response = $this->gateway->createPaymentMethod($request);

// then
Assert::assertEquals('three_d_secure', $response->getType());
Assert::assertNotNull($response->getThreeDSecure());
Assert::assertEquals($request->getThreeDSecure()->getAmount(), $response->getThreeDSecure()->getAmount());
Assert::assertEquals($request->getThreeDSecure()->getCurrency(), $response->getThreeDSecure()->getCurrency());
Assert::assertEquals($request->getSource(), $response->getSource()['id']);
Assert::assertNotNull($response->getFlow());
Assert::assertNotNull($response->getFlow()->getNextAction());
}

function testWillNotCreateDuplicateIfSameIdempotencyKeyIsUsed()
{
// given
Expand Down
44 changes: 44 additions & 0 deletions tests/utils/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
use Shift4\Request\CustomerRequest;
use Shift4\Request\CardRequest;
use Shift4\Request\FraudCheckDataRequest;
use Shift4\Request\PaymentMethodRequest;
use Shift4\Request\PaymentMethodRequestGooglePay;
use Shift4\Request\SubscriptionRequest;
use Shift4\Request\PlanRequest;
use Shift4\Request\ThreeDSecure;
use Shift4\Request\TokenRequest;
use Shift4\Request\BlacklistRuleRequest;
use Shift4\Request\CheckoutRequest;
Expand All @@ -19,6 +22,7 @@
use Shift4\Request\CheckoutRequestThreeDSecure;
use Shift4\Request\CreditRequest;
use Shift4\Request\DisputeEvidenceRequest;
use Shift4\Response\PaymentMethod;

class Data
{
Expand Down Expand Up @@ -249,6 +253,46 @@ public static function billingRequest() {
->vat('billing-vat');
}

/**
* @return PaymentMethodRequest
*/
public static function googlePayPaymentMethodPanOnly()
{
$paymentMethod = new PaymentMethodRequest();
return $paymentMethod
->type("google_pay")
->googlePay((new PaymentMethodRequestGooglePay())
->token("PAN_ONLY"));
}

/**
* @return PaymentMethodRequest
*/
public static function googlePayPaymentMethod3ds()
{
$paymentMethod = new PaymentMethodRequest();
return $paymentMethod
->type("google_pay")
->googlePay((new PaymentMethodRequestGooglePay())
->token("CRYPTOGRAM_3DS"));
}


/**
* @param $source PaymentMethod
* @return PaymentMethodRequest
*/
public static function threeDSecurePaymentMethod($source, $currency, $amount)
{
$paymentMethod = new PaymentMethodRequest();
return $paymentMethod
->type("three_d_secure")
->source($source->getId())
->threeDSecure((new ThreeDSecure())
->currency($currency)
->amount($amount));
}

private static function addressRequest($prefix) {
$address = new AddressRequest();
return $address
Expand Down