diff --git a/README.md b/README.md index 2aede35f..1201714c 100644 --- a/README.md +++ b/README.md @@ -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' @@ -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' diff --git a/composer.json b/composer.json index e7b20571..6a68840f 100644 --- a/composer.json +++ b/composer.json @@ -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 diff --git a/src/Services/ExpressCheckout.php b/src/Services/ExpressCheckout.php index fe2798b0..8676ddab 100644 --- a/src/Services/ExpressCheckout.php +++ b/src/Services/ExpressCheckout.php @@ -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. diff --git a/src/Traits/RecurringProfiles.php b/src/Traits/RecurringProfiles.php new file mode 100644 index 00000000..a246e523 --- /dev/null +++ b/src/Traits/RecurringProfiles.php @@ -0,0 +1,54 @@ + 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); + } +}