Skip to content

Commit

Permalink
Create recurring monthly & yearly subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
srmklive committed Apr 6, 2017
1 parent f7a508a commit 54dc12c
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 4 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ $data['total'] = $total;
'PROFILESTARTDATE' => $startdate,
'DESC' => $profile_desc,
'BILLINGPERIOD' => 'Month', // Can be 'Day', 'Week', 'SemiMonth', 'Month', 'Year'
'BILLINGFREQUENCY' => 12, // set 12 for monthly, 52 for yearly
'BILLINGFREQUENCY' => 1, //
'AMT' => 10, // Billing amount for each billing cycle
'CURRENCYCODE' => 'USD', // Currency code
'TRIALBILLINGPERIOD' => 'Day', // (Optional) Can be 'Day', 'Week', 'SemiMonth', 'Month', 'Year'
Expand Down Expand Up @@ -416,7 +416,7 @@ $data = [
'PROFILESTARTDATE' => $startdate,
'DESC' => "Monthly Subscription #1",
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => 12,
'BILLINGFREQUENCY' => 1,
'AMT' => 9.99,
'INITAMT' => 9.99,
'CURRENCYCODE' => 'USD'
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
},
"require": {
"guzzlehttp/guzzle": "~5.0|~6.0",
"illuminate/support": "~5.0|~5.1|~5.2|~5.3|~5.4"
"illuminate/support": "~5.0|~5.1|~5.2|~5.3|~5.4",
"nesbot/carbon": "~1.0"
},
"config": {
"sort-packages": true
Expand Down
3 changes: 2 additions & 1 deletion src/Services/ExpressCheckout.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Support\Collection;
use Srmklive\PayPal\Traits\PayPalRequest as PayPalAPIRequest;
use Srmklive\PayPal\Traits\RecurringProfiles;

class ExpressCheckout
{
// Integrate PayPal Request trait
use PayPalAPIRequest;
use PayPalAPIRequest, RecurringProfiles;

/**
* PayPal Processor Constructor.
Expand Down
54 changes: 54 additions & 0 deletions src/Traits/RecurringProfiles.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Srmklive\PayPal\Traits;

use Carbon\Carbon;

trait RecurringProfiles
{
/**
* Create recurring subscription on monthly basis.
*
* @param string $token
* @param float $amount
* @param string $description
*
* @return array
*/
public function createMonthlySubscription($token, $amount, $description)
{
$data = [
'PROFILESTARTDATE' => Carbon::now()->toAtomString(),
'DESC' => $description,
'BILLINGPERIOD' => 'Month',
'BILLINGFREQUENCY' => 1,
'AMT' => $amount,
'CURRENCYCODE' => $this->currency,
];

return $this->createRecurringPaymentsProfile($data, $token);
}

/**
* Create recurring subscription on yearly basis.
*
* @param string $token
* @param float $amount
* @param string $description
*
* @return array
*/
public function createYearlySubscription($token, $amount, $description)
{
$data = [
'PROFILESTARTDATE' => Carbon::now()->toAtomString(),
'DESC' => $description,
'BILLINGPERIOD' => 'Year',
'BILLINGFREQUENCY' => 1,
'AMT' => $amount,
'CURRENCYCODE' => $this->currency,
];

return $this->createRecurringPaymentsProfile($data, $token);
}
}

0 comments on commit 54dc12c

Please sign in to comment.