d
Topic
Posts:
2
6 days ago

Billing/Pricing

Hi.

 

I have been searching the forums trying to find an example/answer but have yet to find it. We are developing our app(s) and we need a page that follows the billing confirmation i.e one page that says "Thank you" and leads the merchant to the app and one page that leads the merchant (where?) if their billing has been declined or they declined payment. I hope this question is clear - if anyone has any examples it will help.

 

https://help.shopify.com/en/api/app-store/listing-in-the-app-store/app-requirements-and-success-criteria/app-success-criteria - basically what follows "mercant onboarding"

 

 

i
Replies
RK Member
Posts:
5
5 days ago

Hi,

Check below library if you are using php it is may solve your problem.

<?php
// Codeigniter access check, remove it for direct use
if( !defined( 'BASEPATH' ) ) exit( 'No direct script access allowed' );

class Shopify 
{
    function __construct()
    {
      //Before going to the production test_mode parameter should be true  
      $this->test_mode = false;
      $this->shopify_api_key = SHOPIFY_API_KEY;
      $this->access_token = $this->access_token;
      $this->shop = $this->shop;
    }

    //Create a new charge
    function createCharge($charge_data)
    {
         $url = 'https://'.$this->shopify_api_key.':'.$this->access_token.'@'.$this->shop.'/admin/recurring_application_charges.json';
         $data = array('recurring_application_charge'=>array('name'=>$charge_data['plan'], 'price'=>$charge_data['price'], 'return_url'=>$charge_data['url']));
         if($this->test_mode)
         {
              $data['recurring_application_charge']['test'] = true; 
         }
            // use key 'http' even if you send the request to https://...
             $options = array(
                               'http' => array(
                                                 'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                                                 'method'  => 'POST',
                                                 'content' => http_build_query($data)
                                               )
                              );
            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);
            if ($result === FALSE) { /* Handle error */ }

            $result = json_decode($result);

            if($result->recurring_application_charge->confirmation_url)
            redirect($result->recurring_application_charge->confirmation_url, true);
    }

    //Get charge details
    function getChargeDetails($charge_id=false)
    {
         if($charge_id)
           $url = 'https://'.$this->shopify_api_key.':'.$this->access_token.'@'.$this->access_token.'/admin/recurring_application_charges/'.$charge_id.'.json';
         else
          $url = 'https://'.$this->shopify_api_key.':'.$this->access_token.'@'.$this->shop.'/admin/recurring_application_charges.json?since_id='.$since_id;
         $data = array(); 
         if($this->test_mode)
         { 
              $data['recurring_application_charge']['test'] = true;
         }
            // use key 'http' even if you send the request to https://...
             $options = array(
                               'http' => array(
                                                 'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                                                 'method'  => 'GET',
                                                 'content' => http_build_query($data)
                                               )
                              );
            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);
            if ($result === FALSE) { /* Handle error */ }

            $result = json_decode($result);
            if(!empty($result))
            return $result;
            else
            return false;
     }

    //Activate the charge
    function activateCharge($charge_details)
    {
        $url = 'https://'.$this->shopify_api_key.':'.$this->access_token.'@'.$this->shop.'/admin/recurring_application_charges/'.$charge_details->recurring_application_charge->id.'/activate.json';
         $data = $charge_details;
        
        // use key 'http' even if you send the request to https://...
             $options = array(
                               'http' => array(
                                                 'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                                                 'method'  => 'POST',
                                                 'content' => http_build_query($data)
                                               )
                              );
            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);
            if ($result === FALSE) { /* Handle error */ }

            $result = json_decode($result);
        return $result; 
    } 

    //Cancel Recurring Charge
    function deleteCharge($charge_id)
    {
        $url = 'https://'.$this->shopify_api_key.':'.$this->access_token.'@'.$this->shop.'/admin/recurring_application_charges/'.$charge_id.'.json';
         $data = array();

        // use key 'http' even if you send the request to https://...
             $options = array(
                               'http' => array(
                                                 'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
                                                 'method'  => 'DELETE',
                                                 'content' => http_build_query($data)
                                               )
                              );
            $context  = stream_context_create($options);
            $result = file_get_contents($url, false, $context);
            if ($result === FALSE) { /* Handle error */ }

            $result = json_decode($result);
            return $result;
    }
}
?>

Posts:
2
5 days ago

Thank you I will try this