Dev Mod Stripe Payment Gateway

Discussion in 'Modding/Theme Help' started by pani100, Jul 24, 2018.

  1. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Just starting this thread to work through adding Stripe as a payment gateway.
    To start off we would need to add an extra row in the database ($DBRefix)_payment_options.
    Log into your database (normally through phpMyAdmin) and "copy" the last row (7) - toocheckout.
    Rename it to:
    name: stripe
    display_name: Stripe
    and save.

    Now open validate.php and replace:
    PHP:
    if (isset($_GET['toocheckout'])) {
        
    $fees->toocheckout_validate();
    }
    to
    PHP:
    if (isset($_GET['toocheckout'])) {
        
    $fees->toocheckout_validate();
    }
    if (isset(
    $_GET['stripe'])) {
        
    $fees->stripe_validate();
    }
    Save.
    Open includes/class_fees.php and find around line 224
    PHP:
    private function callback_process($custom_id$fee_type$payment_amount)
    Right above it add stripe function
    PHP:
    public function stripe_validate()
        {
            
    $payment_amount floatval($this->data['x_amount']);
            list(
    $custom_id$fee_type) = explode('WEBID'$this->data['custom']);
            if (
    $this->data['x_response_code'] == 1) {
                
    self::callback_process($custom_id$fee_type$payment_amount);
                
    $redirect_url $this->system->SETTINGS['siteurl'] . 'validate.php?completed';
            } else {
                
    $redirect_url $this->system->SETTINGS['siteurl'] . 'validate.php?fail';
            }

            
    header('location: '$redirect_url);
            exit;
        }
    and save.
    This is not the correct function as I do not know how we will process the stripe call back yet but it is a start.
    Open includes/config/gateways.php and replace with:

    PHP:
    if (!defined('InWeBid')) {
        exit(
    'Access denied');
    }

    $gateway_links = array(
        
    'paypal' => 'http://paypal.com/',
        
    'authnet' => 'http://authorize.net/',
        
    'worldpay' => 'http://rbsworldpay.com/',
        
    'skrill' => 'http://skrill.com/',
        
    'toocheckout' => 'http://2checkout.com/',
        
    'stripe' => 'https://stripe.com/'
        
    );
    $address_string = array(
        
    'paypal' => $MSG['720'],
        
    'authnet' => $MSG['773'],
        
    'worldpay' => $MSG['824'],
        
    'skrill' => $MSG['825'],
        
    'toocheckout' => $MSG['826'],
        
    'stripe' => 'Stripe Public Key'
        
    );
    $password_string = array(
        
    'authnet' => $MSG['774'],
        
    'stripe' => 'Stripe Secret Key'
        
    );
        
    $error_string = array(
        
    'paypal' => $MSG['810'],
        
    'authnet' => $MSG['811'],
        
    'worldpay' => $MSG['823'],
        
    'skrill' => $MSG['822'],
        
    'toocheckout' => $MSG['821'],
        
    'stripe' => 'A valid Public and Secret key are required'
    );
    I have hardcoded the messages for now but we can return on this and add them to our language files.
    Save.
    You should be able to log into the admin and enter your public and private key in the stripe boxes.
    Same for the user side, they should be able to enter their keys too.
    Now we need to work out which version we will be using (2 or 3?) to create the payments and work out a script to use for stripe.
    To return when I get time.
    In the mean time details of ow stripe works can be found here: https://stripe.com/ under devvelopers. Remember if you want to test things do not use your real keys yet, use your test keys.
    Chip in if you have any idea where we go from here.
    I was going to start off in the admin side first so admin fees can be paid via stripe.
     
    Last edited: Jul 24, 2018
  2. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    And we have lift off...!!!
    On the includes/class_fees.php replace the stripe_validate function with the below.
    We have disabled any payment processing but log the stripe webhook response to the error log so we can see when it visits.
    PHP:
    public function stripe_validate()
        {
            global 
    $template$MSG;
           
            
    // Retrieve the request's body and parse it as JSON:
            
    $input = @file_get_contents('php://input');
            
    $event_json json_decode($inputtrue);
            
    $data $event_json['data']['object'];
            
    $success false;
            
    //$paid   = $data['paid'];
            //$custom = $data['description'];
            //$amount = $data['amount']; //->  for later -> $amount = sprintf('$%0.2f', $amount / 100.0);
            
    $payment_amount floatval($data['amount']);
            list(
    $custom_id$fee_type) = explode('WEBID'$data['description']);
            
    $this->system->log('error''<b>Stripe-Webhook</b> paid = ' $data['paid'] . ' | custom = ' $data['description'] . ' | amount = ' $data['amount'] . ' | payment_amount = ' $payment_amount);
            if (
    $data['paid'] == 1) {
                
    //self::callback_process($custom_id, $fee_type, $payment_amount);
                
    $success true;
                
    //$redirect_url = $this->system->SETTINGS['siteurl'] . 'validate.php?completed';
            
    }
           
            
    http_response_code(200);
            
    //return $success;
            
    exit;
        }
    Edit: Sorted the header 200 response. At the moment we do not need to show anything.

    You will need to go to your stripe account and enable webhooks pointing to: {'YOUR_SITE'}/validate.php?stripe
    This will be for test data. Once we make sure things work we have to enable webhooks for the live site too.
     
    Last edited: Jul 25, 2018
  3. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
  4. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    pay1-04.png And... Payments all going through successfully!
    Now to do the other payments.
     
  5. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Got distracted...
     
    Last edited: Jul 25, 2018
  6. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    I have managed to get this working for all payments and is ready for testing before we move it to the mod section.
    Tested on WeBid 2.2.2 Github version.
     

    Attached Files:

  7. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    I think there is an issue with the buy_now.php.
    It has a few missing values and when it says pay now it redirects you to the outstanding.php instead of the pay page.
    I have just quickly moved a closing bracket in the buy_now.php and now all missing vars are present but will need testing and looking at.
    Attached the buy_now.php

    Forgot to mention we have 2 type of stripe modules.
    In pay.php line 27
    $stripe_ckeckout = 0 is the input box type lstipe.js v2
    $stripe_ckeckout = 1 is the popup type (checkout.js)
     

    Attached Files:

    Last edited: Jul 25, 2018
  8. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Attached mod without a key I forgot to remove in the pay.tpl file
     

    Attached Files:

  9. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    And the buy_now.php whithout any echos forgoten
     

    Attached Files:

  10. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Starting to play with the latest stripe version now
     
  11. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Forget about the buy_now.php.
    I will have to have a closer look at why in Live mode standard auctions (with or without buy_now) redirect to outstanding instead of pay.php.
    It is missing the $winner_id which would take it to the pay page.
    Because the standard auction is dealt with by the cron there is no $winner_id declared.
    Buy Now Only items go to the pay.php correctly.
     
  12. pani100

    pani100 Well-Known Member

    Joined:
    May 9, 2011
    Messages:
    2,327
    Likes Received:
    449
    Attached version 2 with latest api.
    If you have tested the previous version, delete the includes/packages/Stripe folder as this has the latest version now.
     

    Attached Files:

  13. TerminalAddict

    TerminalAddict New Member

    Joined:
    Apr 26, 2019
    Messages:
    3
    Likes Received:
    1
    did this ever get completed?

    It's not working for me .. not sure why?
    Nothing in webserver logs, nothing in JS console.
    [​IMG]
     
  14. david62311

    david62311 Well-Known Member

    Joined:
    Aug 29, 2013
    Messages:
    2,116
    Likes Received:
    236

Share This Page