Marketpress Chained Payments Modification

Hey guys,

I wrote a new shipping plugin i needed for the nature of my site. This shipping plugin calculates a shipping cost based on a few factors (size, weight, etc etc) for each individual variation within a product.

The last thing I need to do with this shipping method is modify the chained payments payment splitting to send this calculated shipping cost to one account, and the rest of the total cost to another account.

I havent looked at the code yet, I figured I would check in with you guys for any tips before I dive into things.

So, any tips?

Thanks,

Jack

  • Kimberly
    • Champion of Loops

    Hey Jack!

    Welcome to WPMUdev forums!

    I applaud your "do-it-youself" style! :slight_smile: You are much braver than I!

    The chained payments that is included with Marketpress is handled through PayPal, so I don't think you'll find much in the code for you to modify with Marketpress as far as who gets what. I'm sure there is some modification you can try though.

    You will also still need to get your Chained App submitted and OK'd by x.com

    Best of Luck!

    Kimberly

  • michiganfootball20
    • WPMU DEV Initiate

    My application has been approved, but there is code that dictates how the payment gets split. For instance, somewhere it takes into account the percentage that marketpress allows the site owner to take.

    Im looking for some info on where this code is, and anything i should take into consideration when I am editing.

    Thanks for the quick response kimberly!

    Jack

  • michiganfootball20
    • WPMU DEV Initiate

    Kimberly, I understand that the percentage can be changed. I want to completely alter how the payment is split.

    For example, if a product has a total cost of $100, $25 of which is shipping and $75 of which is the cost of the actual product, I want to send the $25 dollars for shipping to one account (mine), and the $75 dollars to another account (the sellers).

    I am looking for the location in the code, not the admin panel, where I can write new code to make this happen. And in particular, anything I should watch out for when changing this.

    I do feel this is something that should be directed towards a developer.

    Thanks Kimberly!

    Jack

  • Aaron
    • CTO

    This method is where it happens:
    function Pay($cart, $shipping_info, $order_id) {
    in the chained gateway file.

    You can see how it's divided up here:

    //shipping line
        if ( ($shipping_price = $mp->shipping_price()) !== false ) {
          $total = $total + $shipping_price;
        }
    
        //tax line
        if ( ($tax_price = $mp->tax_price()) !== false ) {
          $total = $total + $tax_price;
        }
    
    		//calculate fees
        $fee = round( ($network_settings['gateways']['paypal-chained']['percentage'] * 0.01) * $total, 2);
    
        $nvpstr .= "&receiverList.receiver(0).email=" . urlencode($settings['gateways']['paypal-chained']['email']);
    		$nvpstr .= "&receiverList.receiver(0).amount=" . $total;
    		$nvpstr .= "&receiverList.receiver(0).invoiceId=" . $order_id;
    		$nvpstr .= "&receiverList.receiver(0).paymentType=GOODS";
    		$nvpstr .= "&receiverList.receiver(0).primary=true";
    
    		$nvpstr .= "&receiverList.receiver(1).email=" . urlencode($network_settings['gateways']['paypal-chained']['email']);
    		$nvpstr .= "&receiverList.receiver(1).amount=" . $fee;
    		$nvpstr .= "&receiverList.receiver(1).paymentType=SERVICE";
    		$nvpstr .= "&receiverList.receiver(1).primary=false";

    Note that the store owner is recieiver 0 (primary), and network owner reciever 1.

    Simply replacing $nvpstr .= "&receiverList.receiver(1).amount=" . $fee; with $nvpstr .= "&receiverList.receiver(1).amount=" . $shipping_price; I think would do what you want.

  • michiganfootball20
    • WPMU DEV Initiate

    i lied i have one more question pertaining to this line in the pay function:

    foreach ($cart as $product_id => $variations) {
    
          foreach ($variations as $variation => $data) {
    
          	$totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    
          }
    
        }
    
    		$total = array_sum($totals);

    i need to have the total calculated based on my new metal values if my shipping plugin is selected.

    this is what i have so far, but i dont know how to get the meta values i need for the given variation.

    if($settings['shipping']['method'] == 'gp-shipping'){
    
    	foreach ($cart as $product_id => $variations) {
    
          foreach ($variations as $variation => $data) {
    
          	$totals[] = (Here I need the meta value called mp_product_cost for the given variation) * $data['quantity'];
    
    		$shipping_total[] = (Here I need the meta value called mp_ship_cost for the given variation) * $data['quantity'];
    
          }
    
        }
    
    	}
    
    	else{
    
        foreach ($cart as $product_id => $variations) {
    
          foreach ($variations as $variation => $data) {
    
          	$totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    
          }
    
        }
    
    	}
    
    		$total = array_sum($totals);
    
    		$shhipping_total = array_sum($shipping_total);

    thanks a lot in advance

    Jack

  • Aaron
    • CTO

    Well it all depends how you are storing your values. If it's in an array keyed by the variation key (recommended) then it would be something like this:

    $my_meta = get_post_meta($product_id, 'mp_ship_cost', true);
    $shipping_total[] =  $my_meta[$variation] * $data['quantity'];
  • michiganfootball20
    • WPMU DEV Initiate

    i swear this is my last question..

    if($settings['shipping']['method'] == 'gp-shipping'){
    
    	foreach ($cart as $product_id => $variations) {
    
          foreach ($variations as $variation => $data) {
    
    	  	$ship_meta = get_post_meta($product_id, 'mp_ship_cost', true);
    		$product_meta = get_post_meta($product_id,'mp_product_cost', true);
    
          	$shipping_totals[] = $ship_meta[$variation] * $data['quantity'];
    		$totals[] = $product_meta[$variation] * $data['quantity'];
    
          }
    
        }
    
    	$shipping_total = array_sum($shipping_totals);
    
    	}
    
    	else{
    
        foreach ($cart as $product_id => $variations) {
    
          foreach ($variations as $variation => $data) {
    
          	$totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
    
          }
    
        }
    
    	}
    
    		$total = array_sum($totals);

    that is my code, not sure why but im getting an error. any suggestions?

  • jason_hebert
    • Flash Drive

    I'm doing something similar but I'm trying to take a % as well as the shipping.

    I tried adding

    $nvpstr .= "&receiverList.receiver(1).amount=" . $shipping_price;

    instead of replacing the .$fee line cause I want both but it doesn't work. It's still giving me a percentage of the total price including shipping.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.