Automatic subscription setup and invoice creation based on hosting plan

Discussion in 'Installation and "How-To" Questions' started by Netzhaus, Jul 1, 2014.

  1. Netzhaus

    Netzhaus Kilo Poster

    Messages:
    46
    Situation: We want to offer some hosting plans which will be setup automatically like Plesk hostings and we will offer some miscellaneous plans which need to be checked and set up manually.
    For all these plans we want to offer all our payment options (online payment and and bank transfer).

    As far as I can see, it is only possible to configure the automatic invoice creation and subscription creation depending on payment option.

    Is there a way to configure this depending on the hosting plan?
     
  2. Theloneus

    Theloneus Kilo Poster

    Messages:
    13
    Netzhaus, the way we accomplished this is by running a custom script after subscription creation. You can call a perl script that provisions the particulars.
     
  3. Netzhaus

    Netzhaus Kilo Poster

    Messages:
    46
    Thank you for your reply, Theloneus.
    But at the moment I don't see the way I could do this.
    Did you set all actions in the payment methods to do nothing and then call the scripts by events?
    Are you using the XML API functions in your perl script? (in the documentation I didn't find any functions, which look like as they could help me)
     
  4. Theloneus

    Theloneus Kilo Poster

    Messages:
    13
    Netzhaus,

    For our situation, we wanted to auto-provision more than one plan at a time. To do this, we had add ons that customers can purchase.

    So, when a customer purchases a plan with an add-on, it worked like this:
    The main plan is provisioned normally by PBA-S.
    I created an event (Configuration Director->Event Manager->Events) under the "Subscription has been created" event (Actions tab)
    Select the subscription type you want the script to fire on (for us I just used the "Subscription" option), just click "add action"
    In our case, I made a "custom-scripts" directory in the root of pba-s (755 permissions are sufficient)
    Code:
    cd /custom-scripts;
    perl add-package.pl "@@customer.id@" "##order.custom_attrs#@@name@##/order.custom_attrs#";
    
    Your code will vary. You will need to pass different variables to your script most likely.
    Example script that provisions a plan (this is a generic script and does not work with the event above):
    Code:
    #!/usr/bin/perl
    # to use type perl add-manually [customer_id] [plan_id] [duration]
    # durations:
    # 1 month:  2592000
    # 3 months: 7776000
    # 6 months: 15552000
    # 1 year:   31104000
    # 2 years:  62208000
    # 3 years:  93312000
    # 4 years:  124416000
    # 5 years:  155520000
    
    #should add some checks to prevent weirdness
    
    use strict;
    use CGI;
    
    my $sid = $ARGV[1];
    my $duration = $ARGV[2];
    	
    if( $sid != -1 ){
    	my $order = place_order({
    
    		hp_sid			=> $sid,		# hosting plan series key
    
    		account_id		=> $ARGV[0],	# subscription owner
    
    		period			=> $duration,	# subscription period
    
    		for_trial		=> 0,			# is subscription trial?
    
    		sb_plan			=> undef,		# Sitebuilder site ID for provisioning
    		
    										# If we need to get ssl working, more info is needed here
    		
    		description		=> 'Generated through XML API',
    
    	});
    
    	print "Order #$order->{id} has been successfully generated, provisioning initiated.\n";
    
    	################################################################################
    	# below is code for order generation, alter it *only* to archieve special functionality
    
    	use SOAP::Lite ();
    
    	my $client;
    
    	sub place_order {
    
    		my $order_details = shift;
    
    		$order_details->{is_free} = 1;
    
    		# place order and return its structure
    
    		return $client->ns('HSPC/API/Billing/1.0')->place_order($order_details)->result;
    
    	}
    
    	BEGIN {
    
    		# create XML API client object
    
    		$client = SOAP::Lite
    
    			->proxy('http://localhost:8080/hspc/xml-api')
    
    			->on_fault(sub {
    
    				print 'SOAP Fault: ' . $_[1]->faultcode . ' - ' . $_[1]->faultstring . "\n";
    
    				exit(1);
    
    			});
    
    		# open session: receive session ID for provider
    
    		my $sid = $client->ns('HSPC/API/1.0')->session_open({ account_id => 1 })->result->{session_id};
    
    		# put session ID to outgoing requests' HTTP headers
    
    		$client->transport->http_request->header('HSPC-SID' => $sid);
    
    	}
    
    	END {
    
    		# close session
    
    		$client->ns('HSPC/API/1.0')->session_close;
    
    	}
    }
    
     
  5. Netzhaus

    Netzhaus Kilo Poster

    Messages:
    46
    Thank you for your example,

    you use the XML API as I expected.
    I read the SDK documentation for the XML API, but I could not find any function to create a subscription, what will be necessary for my scenario, as far as I understand it.
    (You use the place_order function, but in my scenario an order is already existing.)
    Maybe I overlooked it.
     
  6. FedorK

    FedorK Mega Poster

    Messages:
    224
    Hello,

    Subscription should be created from order, subscription could not be created without order.
     
  7. Netzhaus

    Netzhaus Kilo Poster

    Messages:
    46
    Hello FedorK,

    and if I have an order? How can I create the corresponding subscription via a script (XML API or anything else)?
     
  8. FedorK

    FedorK Mega Poster

    Messages:
    224
    For process order you should pay it.
     

Share This Page