Skip to content
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
24 changes: 24 additions & 0 deletions com/checkout/ApiServices/Charges/ChargeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,30 @@ public function getChargeHistory($chargeId)
$responseModel = new ResponseModels\ChargeHistory($processCharge);
return $responseModel;
}

/**
* Creates a charge with a local payment
* @param RequestModels\LocalPaymentCharge $requestModel
* @return ResponseModels\Charge
*/
public function chargeWithLocalPayment(RequestModels\LocalPaymentCharge $requestModel)
{

$chargeMapper = new ChargesMapper($requestModel);

$requestPayload = array (
'authorization' => $this->_apiSetting->getSecretKey(),
'mode' => $this->_apiSetting->getMode(),
'postedParam' => $chargeMapper->requestPayloadConverter(),

);

$processCharge = \com\checkout\helpers\ApiHttpClient::postRequest($this->_apiUrl->getLocalPaymentChargesApiUrl(),
$this->_apiSetting->getSecretKey(),$requestPayload);

$responseModel = new ResponseModels\Charge($processCharge);

return $responseModel;
}

}
11 changes: 11 additions & 0 deletions com/checkout/ApiServices/Charges/ChargesMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,17 @@ public function requestPayloadConverter($requestModel = null )
$requestPayload['paymentPlans'][] = $requestSinglePaymentPlan;
}
}

if(method_exists($requestModel,'getBaseLocalPayment') ) {
$baseLocalPayment = $requestModel->getBaseLocalPayment();

$requestPayload['localPayment']['lppId'] = $baseLocalPayment->getLppId();

if ( !empty($baseLocalPayment->getIssuerId()) ) {
$requestPayload['localPayment']['userData']['issuerId'] = $baseLocalPayment->getIssuerId();
}

}

}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
namespace com\checkout\ApiServices\Charges\RequestModels;
/**
* Class LocalPaymentCharge
* @package com\checkout\ApiServives\Charges\RequestModels
* @note make a magic function that convert in the concept of postedParam
*/
class LocalPaymentCharge extends BaseCharge
{

private $_baseLocalPayment;

private $_paymentToken;

/**
* @return \com\checkout\ApiServices\LocalPayment\RequestModels\BaseLocalPayment
*/
public function getBaseLocalPayment ()
{
return $this->_baseLocalPayment;
}

/**
* @param \com\checkout\ApiServices\LocalPayment\RequestModels\BaseLocalPayment $baseLocalPayment
*/
public function setBaseLocalPayment (\com\checkout\ApiServices\LocalPayment\RequestModels\BaseLocalPayment $baseLocalPayment )
{
$this->_baseLocalPayment = $baseLocalPayment;
}

/**
* @return mixed
*/
public function getPaymentToken ()
{
return $this->_paymentToken;
}

/**
* @param mixed $paymentToken
*/
public function setPaymentToken ( $paymentToken )
{
$this->_paymentToken = $paymentToken;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
namespace com\checkout\ApiServices\LocalPayment\RequestModels;

class BaseLocalPayment
{
protected $_lppId;
protected $_issuerId;

/**
* @return string Payment provider ID
*/
public function getLppId()
{
return $this->_lppId;
}

/**
* @return string Issuer ID
*/
public function getIssuerId()
{
return $this->_issuerId;
}

/**
* @param string $lppId Payment provider ID
* @return $this
*/
public function setLppId($lppId)
{
$this->_lppId = $lppId;
return $this;
}

/**
* @param string $issuerId Issuer ID
* @return $this
*/
public function setIssuerId($issuerId)
{
$this->_issuerId = $issuerId;
return $this;
}

}
25 changes: 25 additions & 0 deletions com/checkout/helpers/ApiUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class ApiUrls
private $_recurringPaymentsCustomersApiUri = null;
private $_recurringPaymentsCustomersQueryApiUri = null;
private $_visaCheckoutCardTokenApiUri = null;
private $_localPayementChargesApiUrl = null;

public function __construct()
{
Expand Down Expand Up @@ -592,4 +593,28 @@ public function setVisaCheckoutCardTokenApiUri($visaCheckoutCardTokenApiUri)
{
$this->_visaCheckoutCardTokenApiUri = $visaCheckoutCardTokenApiUri;
}

/**
* get local payment charge url
* @return string
*/
public function getLocalPaymentChargesApiUrl()
{
if (empty($this->_localPayementChargesApiUrl)) {
$this->setLocalPayementChargesApiUrl($this->getBaseApiUri() . "/charges/localpayment");
}
return $this->_localPayementChargesApiUrl;
}

/**
*
* @param string $localPayementChargesApiUrl Local payment charge API url
* @return $this
*/
public function setLocalPayementChargesApiUrl($localPayementChargesApiUrl)
{
$this->_localPayementChargesApiUrl = $localPayementChargesApiUrl;
return $this;
}

}
55 changes: 55 additions & 0 deletions test/ChargeService/ChargeServiceLocalPaymentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
namespace test\ChargeService;
use test\TestHelper;

include '../../autoload.php';

class ChargeServiceTest extends \PHPUnit_Framework_TestCase
{
private $_apiClient ;
private $_customerId;
private $_cardId;

public function setup()
{
// replace by a valid key with alternative payments enabled
$this->_apiClient = new \com\checkout\ApiClient('sk_test_a2dba067-bfe8-425c-88e9-6685820aa16e');

}

public function testChargeWithLocalPayment()
{

$paymentTokenCreate = new \com\checkout\ApiServices\Tokens\RequestModels\PaymentTokenCreate();
$paymentTokenCreate->setValue(100);
$paymentTokenCreate->setCurrency('EUR');
$paymentTokenCreate->setChargeMode('3');
$paymentTokenCreate->setSuccessUrl('http://mycustomerurl.com/order?result=pass');
$paymentTokenCreate->setFailUrl('http://mycustomerurl.com/order?result=fail');

$tokenService = $this->_apiClient->tokenService();
$paymentToken = $tokenService->createPaymentToken($paymentTokenCreate);

$this->baseLocalPayment = new \com\checkout\ApiServices\LocalPayment\RequestModels\BaseLocalPayment();
// iDEAL
$this->baseLocalPayment->setLppId('lpp_9');
$this->baseLocalPayment->setIssuerId('RABONL2U');

$charge = new \com\checkout\ApiServices\Charges\RequestModels\LocalPaymentCharge();
$charge->setBaseLocalPayment($this->baseLocalPayment);
$charge->setPaymentToken($paymentToken->getId());
$charge->setEmail('test@example.org');

$chargeService = $this->_apiClient->chargeService();
$chargeResponse = $chargeService->chargeWithLocalPayment($charge);

$this->assertFalse( $chargeResponse->hasError());
$this->assertEquals(200, $chargeResponse->getHttpStatus());
$this->assertNotNull($chargeResponse->getId());
$this->assertStringStartsWith('https://sandbox.checkout.com', $chargeResponse->getLocalPayment()->getPaymentUrl());

}


}