--- /tmp/dsg/dolibarr/htdocs/stripe/lib/github_stripe.lib.php +++ /tmp/dsg/dolibarr/htdocs/stripe/lib/client_stripe.lib.php @@ -21,8 +21,6 @@ * \brief Library for common stripe functions */ -require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; - /** * Define head array for tabs of stripe tools setup pages * @@ -42,15 +40,96 @@ $object = new stdClass(); - // Show more tabs from modules - // Entries must be declared in modules descriptor with line - // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab - // $this->tabs = array('entity:-tabname); to remove a tab + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab complete_head_from_modules($conf, $langs, $object, $head, $h, 'stripeadmin'); complete_head_from_modules($conf, $langs, $object, $head, $h, 'stripeadmin', 'remove'); - return $head; + return $head; +} + + + +/** + * Return string with full Url + * + * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) + * @param string $ref Ref of object + * @return string Url string + */ +function showStripePaymentUrl($type, $ref) +{ + global $conf, $langs; + + $langs->load("paypal"); + $langs->load("paybox"); + $langs->load("stripe"); + + $servicename = 'Stripe'; + $out = '

'; + $out .= img_picto('', 'globe').' '.$langs->trans("ToOfferALinkForOnlinePayment", $servicename).'
'; + $url = getStripePaymentUrl(0, $type, $ref); + $out .= '
'; + $out .= ajax_autoselect("stripeurl", 0); + return $out; +} + +/** + * Return string with full Url + * + * @param int $mode 0=True url, 1=Url formated with colors + * @param string $type Type of URL ('free', 'order', 'invoice', 'contractline', 'membersubscription' ...) + * @param string $ref Ref of object + * @param int $amount Amount + * @param string $freetag Free tag + * @return string Url string + */ +function getStripePaymentUrl($mode, $type, $ref = '', $amount = '9.99', $freetag = 'your_tag') +{ + global $conf; + + $ref = str_replace(' ', '', $ref); + + if ($type == 'free') + { + $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?amount='.($mode ? '' : '').$amount.($mode ? '' : '').'&tag='.($mode ? '' : '').$freetag.($mode ? '' : ''); + } + if ($type == 'order') + { + $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=order&ref='.($mode ? '' : ''); + if ($mode == 1) $out .= 'order_ref'; + if ($mode == 0) $out .= urlencode($ref); + $out .= ($mode ? '' : ''); + } + if ($type == 'invoice') + { + $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=invoice&ref='.($mode ? '' : ''); + if ($mode == 1) $out .= 'invoice_ref'; + if ($mode == 0) $out .= urlencode($ref); + $out .= ($mode ? '' : ''); + } + if ($type == 'contractline') + { + $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=contractline&ref='.($mode ? '' : ''); + if ($mode == 1) $out .= 'contractline_ref'; + if ($mode == 0) $out .= urlencode($ref); + $out .= ($mode ? '' : ''); + } + if ($type == 'membersubscription') + { + $out = DOL_MAIN_URL_ROOT.'/public/stripe/newpayment.php?source=membersubscription&ref='.($mode ? '' : ''); + if ($mode == 1) $out .= 'member_ref'; + if ($mode == 0) $out .= urlencode($ref); + $out .= ($mode ? '' : ''); + } + + // For multicompany + $out .= "&entity=".$conf->entity; // Check the entity because He may be the same reference in several entities + + return $out; }