|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright (c) 2019 PayGate (Pty) Ltd |
| 4 | + * |
| 5 | + * Author: App Inlet (Pty) Ltd |
| 6 | + * |
| 7 | + * Released under the GNU General Public License |
| 8 | + * |
| 9 | + */ |
| 10 | +use Illuminate\Database\Capsule\Manager as Capsule; |
| 11 | + |
| 12 | +function paysubslink_config() |
| 13 | +{ |
| 14 | + $configarray = [ |
| 15 | + "FriendlyName" => ["Type" => "System", "Value" => "PaySubs"], |
| 16 | + "merchantid" => ["FriendlyName" => "Terminal ID", "Type" => "text", "Size" => "20"], |
| 17 | + "secret" => ["FriendlyName" => "Secret", "Type" => "password", "Size" => "30"], |
| 18 | + "budget" => array( "FriendlyName" => "Accept PaySubs Budget Payments", "Type" => "yesno" ), |
| 19 | + "recurring" => array( "FriendlyName" => "Enable Recurring", "Type" => "yesno" ), |
| 20 | + ]; |
| 21 | + return $configarray; |
| 22 | +} |
| 23 | + |
| 24 | +function paysubslink_link( $params ) |
| 25 | +{ |
| 26 | + $invoice = Capsule::table( 'tblinvoices' )->join( 'tblinvoiceitems', 'tblinvoiceitems.invoiceid', '=', 'tblinvoices.id' )->where( 'tblinvoices.id', $params['invoiceid'] )->first(); |
| 27 | + $invoiceNumber = 'Invoice ' . $params['invoicenum']; |
| 28 | + $description = $params["description"]; |
| 29 | + $amount = $params['amount']; # Format: ##.## |
| 30 | + $currency = $params['currency']; # Currency Code |
| 31 | + $companyname = $params['companyname']; |
| 32 | + $systemurl = $params['systemurl']; |
| 33 | + $currency = $params['currency']; |
| 34 | + $gatewaymerchantid = $params['merchantid']; |
| 35 | + $gatewaybudget = $params['budget']; |
| 36 | + $gatewayrecurring = $params['recurring']; |
| 37 | + $customerID = $params['clientdetails']['userid']; |
| 38 | + $serviceId = $invoice->relid; |
| 39 | + $invoiceId = $params['invoiceid']; |
| 40 | + if ( $gatewaybudget == 1 || $gatewaybudget == 'on' ) { |
| 41 | + $gatewaybudget = 'Y'; |
| 42 | + } else { |
| 43 | + $gatewaybudget = 'N'; |
| 44 | + } |
| 45 | + if ( $gatewayrecurring == 1 || $gatewayrecurring == 'on' ) { |
| 46 | + $gatewayrecurring = true; |
| 47 | + } else { |
| 48 | + $gatewayrecurring = false; |
| 49 | + } |
| 50 | + $return_url = $params['systemurl'] . 'modules/gateways/callback/paysubslink.php'; |
| 51 | + $cancelUrl = $params['returnurl']; |
| 52 | + $hash = $gatewaymerchantid . $invoiceNumber . $params['description'] . $amount . $params['currency'] . $cancelUrl . $gatewaybudget . $email . $invoiceId . $customerID . $serviceId . $params['secret']; |
| 53 | + $hash = md5( $hash ); |
| 54 | + |
| 55 | + $invoices = Capsule::table( 'tblinvoices' )->join( 'tblinvoiceitems', 'tblinvoiceitems.invoiceid', '=', 'tblinvoices.id' )->where( 'tblinvoices.id', $params['invoiceid'] )->get(); |
| 56 | + $subscription = ''; |
| 57 | + foreach ( $invoices as $invoice ) { |
| 58 | + if ( !$invoice->type ) { |
| 59 | + } elseif ( $invoice->type == 'Hosting' ) { |
| 60 | + $service = Capsule::table( 'tblhosting' )->where( 'id', $invoice->relid )->first(); |
| 61 | + switch ( $service->billingcycle ) { |
| 62 | + case 'Daily': |
| 63 | + $paymentInterval = 'D'; |
| 64 | + break; |
| 65 | + case 'Weekly': |
| 66 | + $paymentInterval = 'W'; |
| 67 | + break; |
| 68 | + case 'Monthly': |
| 69 | + $paymentInterval = 'M'; |
| 70 | + break; |
| 71 | + case 'Quarterly': |
| 72 | + $paymentInterval = 'Q'; |
| 73 | + break; |
| 74 | + case 'Semi-Annually': |
| 75 | + $paymentInterval = '6'; |
| 76 | + break; |
| 77 | + case 'Annually': |
| 78 | + $paymentInterval = 'Y'; |
| 79 | + break; |
| 80 | + default: |
| 81 | + $paymentInterval = 0; |
| 82 | + } |
| 83 | + if ( $subscription && ( $subscription != $paymentInterval ) ) { |
| 84 | + $subscription = ''; |
| 85 | + break; |
| 86 | + } |
| 87 | + $subscription = $paymentInterval; |
| 88 | + } else { |
| 89 | + $service = Capsule::table( 'tbldomains' )->where( 'id', $invoice->relid )->first(); |
| 90 | + switch ( $domain->registrationperiod ) { |
| 91 | + case '1': |
| 92 | + $paymentInterval = 'Y'; |
| 93 | + break; |
| 94 | + default: |
| 95 | + $paymentInterval = 0; |
| 96 | + } |
| 97 | + if ( $subscription && ( $subscription != $paymentInterval ) ) { |
| 98 | + $subscription = ''; |
| 99 | + break; |
| 100 | + } else { |
| 101 | + $subscription = $paymentInterval; |
| 102 | + } |
| 103 | + |
| 104 | + } |
| 105 | + } |
| 106 | + if ( !$subscription ) { |
| 107 | + $gatewayrecurring = false; |
| 108 | + } |
| 109 | + if ( !$gatewayrecurring ) { |
| 110 | + $html = '<form method="post" action="https://www.vcs.co.za/vvonline/vcspay.aspx"> |
| 111 | + <input type="hidden" name="p1" value="' . $gatewaymerchantid . '" /> |
| 112 | + <input type="hidden" name="p2" value="' . $invoiceNumber . '" /> |
| 113 | + <input type="hidden" name="p3" value="' . $description . '" /> |
| 114 | + <input type="hidden" name="p4" value="' . $amount . '" /> |
| 115 | + <input type="hidden" name="p5" value="' . $currency . '" /> |
| 116 | + <input type="hidden" name="p10" value="' . $cancelUrl . '" /> |
| 117 | + <input type="hidden" name="Budget" value="' . $gatewaybudget . '" /> |
| 118 | + <input type="hidden" name="CardHolderEmail" value="' . $email . '" /> |
| 119 | + <input type="hidden" name="m_5" value="' . $invoiceId . '" /> |
| 120 | + <input type="hidden" name="m_6" value="' . $customerID . '" /> |
| 121 | + <input type="hidden" name="m_7" value="' . $serviceId . '" /> |
| 122 | + <input type="hidden" name="m_8" value="" /> |
| 123 | + <input type="hidden" name="m_9" value="" /> |
| 124 | + <input type="hidden" name="m_10" value="" /> |
| 125 | + <input type="hidden" name="hash" value="' . $hash . '" /> |
| 126 | + <input type="hidden" name="UrlsProvided" value="Y" /> |
| 127 | + <input type="hidden" name="ApprovedUrl" value="' . $return_url . '" /> |
| 128 | + <input type="hidden" name="DeclinedUrl" value="' . $return_url . '" /> |
| 129 | + <input type="submit" class="btn btn-default" value="Pay (Once-Off)" /> |
| 130 | + </form>'; |
| 131 | + } else { |
| 132 | + $hash = $gatewaymerchantid . $invoiceNumber . $params['description'] . $amount . $params['currency'] . 'U' . $paymentInterval . $cancelUrl . $gatewaybudget . $email . $invoiceId . $customerID . $serviceId . $params['secret']; |
| 133 | + $hash = md5( $hash ); |
| 134 | + $html = '<form method="post" action="https://www.vcs.co.za/vvonline/vcspay.aspx"> |
| 135 | + <input type="hidden" name="p1" value="' . $gatewaymerchantid . '" /> |
| 136 | + <input type="hidden" name="p2" value="' . $invoiceNumber . '" /> |
| 137 | + <input type="hidden" name="p3" value="' . $description . '" /> |
| 138 | + <input type="hidden" name="p4" value="' . $amount . '" /> |
| 139 | + <input type="hidden" name="p5" value="' . $currency . '" /> |
| 140 | + <input type="hidden" name="p6" value="U" /> |
| 141 | + <input type="hidden" name="p7" value="' . $subscription . '" /> |
| 142 | + <input type="hidden" name="p10" value="' . $cancelUrl . '" /> |
| 143 | + <input type="hidden" name="Budget" value="' . $gatewaybudget . '" /> |
| 144 | + <input type="hidden" name="CardHolderEmail" value="' . $email . '" /> |
| 145 | + <input type="hidden" name="m_5" value="' . $invoiceId . '" /> |
| 146 | + <input type="hidden" name="m_6" value="' . $customerID . '" /> |
| 147 | + <input type="hidden" name="m_7" value="' . $serviceId . '" /> |
| 148 | + <input type="hidden" name="m_8" value="" /> |
| 149 | + <input type="hidden" name="m_9" value="" /> |
| 150 | + <input type="hidden" name="m_10" value="" /> |
| 151 | + <input type="hidden" name="hash" value="' . $hash . '" /> |
| 152 | + <input type="hidden" name="UrlsProvided" value="Y" /> |
| 153 | + <input type="hidden" name="ApprovedUrl" value="' . $return_url . '" /> |
| 154 | + <input type="hidden" name="DeclinedUrl" value="' . $return_url . '" /> |
| 155 | + <input type="submit" class="btn btn-default" value="Pay (Recurring)" /> |
| 156 | + </form>'; |
| 157 | + } |
| 158 | + return $html; |
| 159 | +} |
0 commit comments