PayWithAmazon\Client::makeChargeCalls PHP Method

makeChargeCalls() private method

* makeChargeCalls - makes API calls based off the charge type (OrderReference or BillingAgreement)
private makeChargeCalls ( $chargeType, $setParameters, $confirmParameters, $authorizeParameters )
    private function makeChargeCalls($chargeType, $setParameters, $confirmParameters, $authorizeParameters)
    {
        switch ($chargeType) {
            case 'OrderReference':
                // Get the Order Reference details and feed the response object to the ResponseParser
                $responseObj = $this->getOrderReferenceDetails($setParameters);
                // Call the function getOrderReferenceDetailsStatus in ResponseParser.php providing it the XML response
                // $oroStatus is an array containing the State of the Order Reference ID
                $oroStatus = $responseObj->getOrderReferenceDetailsStatus($responseObj->toXml());
                if ($oroStatus['State'] === 'Draft') {
                    $response = $this->setOrderReferenceDetails($setParameters);
                    if ($this->success) {
                        $this->confirmOrderReference($confirmParameters);
                    }
                }
                $responseObj = $this->getOrderReferenceDetails($setParameters);
                // Check the Order Reference Status again before making the Authorization.
                $oroStatus = $responseObj->getOrderReferenceDetailsStatus($responseObj->toXml());
                if ($oroStatus['State'] === 'Open') {
                    if ($this->success) {
                        $response = $this->Authorize($authorizeParameters);
                    }
                }
                if ($oroStatus['State'] != 'Open' && $oroStatus['State'] != 'Draft') {
                    throw new \Exception('The Order Reference is in the ' . $oroStatus['State'] . " State. It should be in the Draft or Open State");
                }
                return $response;
            case 'BillingAgreement':
                // Get the Billing Agreement details and feed the response object to the ResponseParser
                $responseObj = $this->getBillingAgreementDetails($setParameters);
                // Call the function getBillingAgreementDetailsStatus in ResponseParser.php providing it the XML response
                // $baStatus is an array containing the State of the Billing Agreement
                $baStatus = $responseObj->getBillingAgreementDetailsStatus($responseObj->toXml());
                if ($baStatus['State'] === 'Draft') {
                    $response = $this->setBillingAgreementDetails($setParameters);
                    if ($this->success) {
                        $response = $this->confirmBillingAgreement($confirmParameters);
                    }
                }
                // Check the Billing Agreement status again before making the Authorization.
                $responseObj = $this->getBillingAgreementDetails($setParameters);
                $baStatus = $responseObj->getBillingAgreementDetailsStatus($responseObj->toXml());
                if ($this->success && $baStatus['State'] === 'Open') {
                    $response = $this->authorizeOnBillingAgreement($authorizeParameters);
                }
                if ($baStatus['State'] != 'Open' && $baStatus['State'] != 'Draft') {
                    throw new \Exception('The Billing Agreement is in the ' . $baStatus['State'] . " State. It should be in the Draft or Open State");
                }
                return $response;
        }
    }