Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankit Tyagi committed May 29, 2014
2 parents ad01eba + c5e8f10 commit 32d6dce
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Credibility/LaravelCybersource/Cybersource.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ public function getSubscriptionStatus($subscriptionId)
* @param $frequency
* @param bool $autoRenew
* @param null $startDate
* @param null $merchantReferenceNumber
* @return \Credibility\LaravelCybersource\models\CybersourceResponse
*/
public function createSubscription($paymentToken, $productTitle, $amount, $frequency, $autoRenew = true, $startDate = null)
public function createSubscription($paymentToken, $productTitle, $amount, $frequency, $autoRenew = true, $startDate = null, $merchantReferenceNumber = null)
{
$request = $this->createNewSubscriptionRequest($paymentToken, $productTitle,
$amount, $frequency, $autoRenew, $startDate
$amount, $frequency, $autoRenew, $startDate, $merchantReferenceNumber
);
return $this->sendRequest($request);
}
Expand Down Expand Up @@ -185,10 +186,11 @@ public function createOneTimeChargeRequest($amount, $paymentToken)
}

public function createNewSubscriptionRequest($paymentToken, $productTitle, $amount,
$frequency = 'weekly', $autoRenew = 'true', $startDate = null)
$frequency = 'weekly', $autoRenew = 'true', $startDate = null,
$merchantReferenceNumber = null)
{
$startDate = empty($startDate) ? $this->getTodaysDate() : $startDate;
$request = $this->createNewRequest();
$request = $this->createNewRequest($merchantReferenceNumber);

$paySubscriptionCreateService = new CybersourceSOAPModel();
$paySubscriptionCreateService->run = 'true';
Expand Down Expand Up @@ -265,13 +267,14 @@ public function createCancelSubscriptionRequest($subscriptionId)



public function createNewRequest()
public function createNewRequest($merchantReferenceNumber = null)
{
$ref = is_null($merchantReferenceNumber) ? $this->app->make('config')->get('laravel-cybersource::merchant_reference_code') : $merchantReferenceNumber;
return new CybersourceSOAPModel(
'PHP', phpversion(),
$this->app->environment(),
$this->app->make('config')->get('laravel-cybersource::merchant_id'),
$this->app->make('config')->get('laravel-cybersource::merchant_reference_code')
$ref
);
}

Expand Down
22 changes: 22 additions & 0 deletions tests/CybersourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@ public function testCreateNewSubscriptionRequestCreatesProperRequest()
$this->assertEquals(date('Ymd'), $startDate);
}

public function testCreateNewSubscriptionWithMerchantReferenceNumber()
{
$paymentToken = 'test123';
$productTitle = 'Test Title';
$amount = 100.00;

$request = $this->cybersource->createNewSubscriptionRequest($paymentToken, $productTitle,
$amount, 'weekly', 'true', null, 'merchant_ref_num');

$startDate = $request->recurringSubscriptionInfo->startDate;
$autoRenew = $request->recurringSubscriptionInfo->automaticRenew;
$frequency = $request->recurringSubscriptionInfo->frequency;

$this->assertEquals('merchant_ref_num', $request->merchantReferenceCode);
$this->assertEquals($paymentToken, $request->paySubscriptionCreateService->paymentRequestID);
$this->assertEquals($productTitle, $request->subscription->title);
$this->assertEquals($amount, $request->recurringSubscriptionInfo->amount);
$this->assertEquals('weekly', $frequency);
$this->assertEquals('true', $autoRenew);
$this->assertEquals(date('Ymd'), $startDate);
}

public function testCreateUpdateSubscriptionRequest()
{
$paymentToken = 'test123';
Expand Down

0 comments on commit 32d6dce

Please sign in to comment.