Skip to content

Commit 5573f99

Browse files
Navneet RaiNavneet Rai
Navneet Rai
authored and
Navneet Rai
committed
Updated Readme with processor methods
1 parent 12c4f91 commit 5573f99

File tree

1 file changed

+109
-3
lines changed

1 file changed

+109
-3
lines changed

README.md

Lines changed: 109 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,17 @@ return [
9494
|--------------------------------------------------------------------------
9595
*/
9696

97-
/**
98-
* Consumers
99-
*/
97+
/*
98+
|--------------------------------------------------------------------------
99+
| Subscription Services
100+
|--------------------------------------------------------------------------
101+
|
102+
| This file is for storing the credentials for subscription services such
103+
| as Paypal, CCNow, 2Checkout, and others. This file provides a sane
104+
| default location for this type of information, allowing packages
105+
| to have a conventional place to find your various credentials.
106+
|
107+
*/
100108
'services' => [
101109
'paypal'=>[
102110
'email'=>'',
@@ -121,3 +129,101 @@ Just follow the steps below and you will be able to get a processor:
121129
```php
122130
$paypal = Subscription::processor('Paypal');
123131
```
132+
133+
#### Getting Processor Informationation
134+
135+
You can get basic Information for any processor by:
136+
137+
```php
138+
$processor = Subscription::processor($proc);
139+
140+
$info = $processor->info();
141+
```
142+
143+
The value returned is a ``ProcessorInfo`` object. You can call ``getName``, ``getLogo`` and ``getUrl`` methods on this processor to display Processor Name, Logo and Website Url for display purposes.
144+
145+
For ``getLogo`` method to work correctly you'll need to copy package assets to your project using
146+
147+
```
148+
$ php artisan vendor:publish --provider="Userdesk\Subscription\SubscriptionServiceProvider"
149+
```
150+
151+
#### Completing Subscription
152+
153+
Once you have the processor object you can call:
154+
155+
```php
156+
$processor = Subscription::processor($proc);
157+
158+
$processor->complete($id, $product, $consumer);
159+
```
160+
161+
Complete method redirects to source processor so that your user can complete his payment.
162+
163+
``$id`` is your unique Order ID. ``$product`` and ``$consumer`` are objects implementing ``SubscriptionProductContract`` and ``SubscriptionConsumerContract`` respectively.
164+
165+
A basic implementation of ``SubscriptionProductContract`` and ``SubscriptionConsumerContract`` are included with source in form of ``Classes\SubscriptionProduct`` and ``Classes\SubscriptionConsumer`` respectively.
166+
167+
#### Handling Processor Notifications
168+
169+
You can handle Processor Notifications and Processor Cart Return Data by forwarding them to ``ipn`` and ``pdt`` functions respectively.
170+
171+
Both these function excpects only one input with request data as array and returns ``TransactionResult`` object.
172+
173+
```php
174+
public function cartComplete(Request $request, $proc){
175+
$processor = Subscription::processor($proc);
176+
try{
177+
$result = $processor->pdt($request->all());
178+
}catch(TransactionException $exception){
179+
Log::error($exception->getMessage(), $exception->getData());
180+
}
181+
182+
if(!empty($result)){
183+
$cartId = $result->getId();
184+
if(!empty($cartId)){
185+
$action = $result->getAction();
186+
if($action=='signup'){
187+
//Handle successful Signup
188+
}
189+
}else{
190+
Log::error('Cart Not Found For PDT', ['proc'=>$proc, 'data'=>$request->all()]);
191+
}
192+
}
193+
}
194+
```
195+
196+
```php
197+
public function handleIpn(Request $request, $proc){
198+
$processor = Subscription::processor($proc);
199+
try{
200+
$result = $processor->ipn($request->all());
201+
}catch(Userdesk\Subscription\Exceptions\TransactionException $exception){
202+
//Handle Exceptions
203+
Log::error($exception->getMessage(), $exception->getData());
204+
}
205+
206+
if(!empty($result)){
207+
$cartId = $result->getId();
208+
if(!empty($cartId)){
209+
$action = $result->getAction();
210+
211+
if($action=='signup'){
212+
//Handle Signup Code
213+
}else if($action=='payment'){
214+
$transactionId = $result->getIdent();
215+
$amount = $result->getAmount();
216+
//Handle successful payments
217+
}else if($action=='refund'){
218+
$transactionId = $result->getIdent();
219+
$amount = $result->getAmount();
220+
//Handle refunds
221+
}else if($action=='cancel'){
222+
//Handle cancellations;
223+
}
224+
}else{
225+
Log::error('Cart Not Found For IPN', ['proc'=>$proc, 'data'=>$request->all()]);
226+
}
227+
}
228+
}
229+
```

0 commit comments

Comments
 (0)