@@ -570,7 +570,8 @@ public function generateCSR()
570570 */
571571 public function finalizeOrder ($ csr = '' )
572572 {
573- if ($ this ->status == 'pending ' || $ this ->status == 'ready ' )
573+ $ this ->updateOrderData ();
574+ if ($ this ->status == 'ready ' )
574575 {
575576 if ($ this ->allAuthorizationsValid ())
576577 {
@@ -623,7 +624,7 @@ public function finalizeOrder($csr = '')
623624 */
624625 public function isFinalized ()
625626 {
626- return ($ this ->status == 'processing ' || $ this ->status == 'valid ' || $ this -> status == ' ready ' );
627+ return ($ this ->status == 'processing ' || $ this ->status == 'valid ' );
627628 }
628629
629630 /**
@@ -646,48 +647,59 @@ public function getCertificate()
646647 $ this ->updateOrderData ();
647648 $ polling ++;
648649 }
649- if (( $ this ->status == 'valid ' || $ this -> status == ' ready ' ) && ! empty ( $ this -> certificateURL ) )
650+ if ($ this ->status == 'valid ' )
650651 {
651- $ sign = $ this ->connector ->signRequestKid ('' , $ this ->connector ->accountURL , $ this ->certificateURL );
652- $ post = $ this ->connector ->post ($ this ->certificateURL , $ sign );
653- if ($ post ['status ' ] === 200 )
652+ if (!empty ($ this ->certificateURL ))
654653 {
655- if (preg_match_all ('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i ' , $ post ['body ' ], $ matches ))
654+ $ sign = $ this ->connector ->signRequestKid ('' , $ this ->connector ->accountURL , $ this ->certificateURL );
655+ $ post = $ this ->connector ->post ($ this ->certificateURL , $ sign );
656+ if ($ post ['status ' ] === 200 )
656657 {
657- if (isset ($ this ->certificateKeys ['certificate ' ])) file_put_contents ($ this ->certificateKeys ['certificate ' ], $ matches [0 ][0 ]);
658-
659- if (count ($ matches [0 ]) > 1 && isset ($ this ->certificateKeys ['fullchain_certificate ' ]))
658+ if (preg_match_all ('~(-----BEGIN\sCERTIFICATE-----[\s\S]+?-----END\sCERTIFICATE-----)~i ' , $ post ['body ' ], $ matches ))
660659 {
661- $ fullchain = $ matches [0 ][0 ]."\n" ;
662- for ($ i =1 ;$ i <count ($ matches [0 ]);$ i ++)
660+ if (isset ($ this ->certificateKeys ['certificate ' ])) file_put_contents ($ this ->certificateKeys ['certificate ' ], $ matches [0 ][0 ]);
661+
662+ if (count ($ matches [0 ]) > 1 && isset ($ this ->certificateKeys ['fullchain_certificate ' ]))
663+ {
664+ $ fullchain = $ matches [0 ][0 ]."\n" ;
665+ for ($ i =1 ;$ i <count ($ matches [0 ]);$ i ++)
666+ {
667+ $ fullchain .= $ matches [0 ][$ i ]."\n" ;
668+ }
669+ file_put_contents (trim ($ this ->certificateKeys ['fullchain_certificate ' ]), $ fullchain );
670+ }
671+ if ($ this ->log instanceof \Psr \Log \LoggerInterface)
663672 {
664- $ fullchain .= $ matches [ 0 ][ $ i ]. "\n" ;
673+ $ this -> log -> info ( ' Certificate for \'' . $ this -> basename . '\' saved ' ) ;
665674 }
666- file_put_contents (trim ($ this ->certificateKeys ['fullchain_certificate ' ]), $ fullchain );
675+ elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Certificate for \'' . $ this ->basename . '\' saved ' , 'function getCertificate ' );
676+ return true ;
667677 }
668- if ( $ this -> log instanceof \ Psr \ Log \LoggerInterface)
678+ else
669679 {
670- $ this ->log ->info ('Certificate for \'' . $ this ->basename . '\' saved ' );
680+ if ($ this ->log instanceof \Psr \Log \LoggerInterface)
681+ {
682+ $ this ->log ->info ('Received invalid certificate for \'' . $ this ->basename . '\'. Cannot save certificate. ' );
683+ }
684+ elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Received invalid certificate for \'' . $ this ->basename . '\'. Cannot save certificate. ' , 'function getCertificate ' );
671685 }
672- elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Certificate for \'' . $ this ->basename . '\' saved ' , 'function getCertificate ' );
673- return true ;
674686 }
675687 else
676688 {
677689 if ($ this ->log instanceof \Psr \Log \LoggerInterface)
678690 {
679- $ this ->log ->info ('Received invalid certificate for \'' . $ this ->basename . '\'. Cannot save certificate. ' );
691+ $ this ->log ->info ('Invalid response for certificate request for \'' . $ this ->basename . '\'. Cannot save certificate. ' );
680692 }
681- elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Received invalid certificate for \'' . $ this ->basename . '\'. Cannot save certificate. ' , 'function getCertificate ' );
693+ elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Invalid response for certificate request for \'' . $ this ->basename . '\'. Cannot save certificate. ' , 'function getCertificate ' );
682694 }
683695 }
684696 else
685697 {
686698 if ($ this ->log instanceof \Psr \Log \LoggerInterface)
687699 {
688- $ this ->log ->info ('Invalid response for certificate request for \'' . $ this ->basename . '\'. Cannot save certificate. ' );
700+ $ this ->log ->info ('Order for \'' . $ this ->basename . '\' not valid . Cannot find certificate URL . ' );
689701 }
690- elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Invalid response for certificate request for \'' . $ this ->basename . '\'. Cannot save certificate. ' , 'function getCertificate ' );
702+ elseif ($ this ->log >= LEClient::LOG_STATUS ) LEFunctions::log ('Order for \'' . $ this ->basename . '\' not valid . Cannot find certificate URL . ' , 'function getCertificate ' );
691703 }
692704 }
693705 else
0 commit comments