-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from CyberSource/feature/add-samples
Update Sample codes for Flex microform in GitHub
- Loading branch information
Showing
5 changed files
with
335 additions
and
27 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
Samples/FlexMicroform/GenerateCaptureContextAcceptCard.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
require_once __DIR__ . DIRECTORY_SEPARATOR . '../../vendor/autoload.php'; | ||
require_once __DIR__ . DIRECTORY_SEPARATOR . '../../Resources/ExternalConfiguration.php'; | ||
|
||
function GenerateCaptureContextAcceptCard() | ||
{ | ||
$targetOrigins = array(); | ||
$targetOrigins[0] = "https://www.test.com"; | ||
$allowedCardNetworks = array(); | ||
$allowedCardNetworks[0] = "VISA"; | ||
$allowedCardNetworks[1] = "MASTERCARD"; | ||
$allowedCardNetworks[2] = "AMEX"; | ||
$allowedCardNetworks[3] = "CARNET"; | ||
$allowedCardNetworks[4] = "CARTESBANCAIRES"; | ||
$allowedCardNetworks[5] = "CUP"; | ||
$allowedCardNetworks[6] = "DINERSCLUB"; | ||
$allowedCardNetworks[7] = "DISCOVER"; | ||
$allowedCardNetworks[8] = "EFTPOS"; | ||
$allowedCardNetworks[9] = "ELO"; | ||
$allowedCardNetworks[10] = "JCB"; | ||
$allowedCardNetworks[11] = "JCREW"; | ||
$allowedCardNetworks[12] = "MADA"; | ||
$allowedCardNetworks[13] = "MAESTRO"; | ||
$allowedCardNetworks[14] = "MEEZA"; | ||
$allowedPaymentTypes = array(); | ||
$allowedPaymentTypes[0] = "CARD"; | ||
$requestObjArr = [ | ||
"clientVersion" => "v2", | ||
"targetOrigins" => $targetOrigins, | ||
"allowedCardNetworks" => $allowedCardNetworks, | ||
"allowedPaymentTypes" => $allowedPaymentTypes | ||
|
||
]; | ||
$requestObj = new CyberSource\Model\GenerateCaptureContextRequest($requestObjArr); | ||
|
||
|
||
$commonElement = new CyberSource\ExternalConfiguration(); | ||
$config = $commonElement->ConnectionHost(); | ||
$merchantConfig = $commonElement->merchantConfigObject(); | ||
|
||
$apiClient = new CyberSource\ApiClient($config, $merchantConfig); | ||
$apiInstance = new CyberSource\Api\MicroformIntegrationApi($apiClient); | ||
|
||
try { | ||
$apiResponse = $apiInstance->generateCaptureContext($requestObj); | ||
print_r(PHP_EOL); | ||
print_r($apiResponse); | ||
|
||
return $apiResponse; | ||
} catch (Cybersource\ApiException $e) { | ||
print_r($e->getResponseBody()); | ||
print_r($e->getMessage()); | ||
} | ||
} | ||
|
||
if (!defined('DO_NOT_RUN_SAMPLES')) { | ||
echo "\GenerateCaptureContextAcceptCard Sample Code is Running..." . PHP_EOL; | ||
GenerateCaptureContextAcceptCard(); | ||
} | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
Samples/UnifiedCheckout/GenerateCaptureContextForClickToPayDropInUI.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
require_once __DIR__ . DIRECTORY_SEPARATOR . '../../vendor/autoload.php'; | ||
require_once __DIR__ . DIRECTORY_SEPARATOR . '../../Resources/ExternalConfiguration.php'; | ||
|
||
function GenerateCaptureContextForClickToPayDropInUI() | ||
{ | ||
$targetOrigins = array(); | ||
$targetOrigins[0] = "https://yourCheckoutPage.com"; | ||
$allowedCardNetworks = array(); | ||
$allowedCardNetworks[0] = "VISA"; | ||
$allowedCardNetworks[1] = "MASTERCARD"; | ||
$allowedCardNetworks[2] = "AMEX"; | ||
$allowedCardNetworks[3] = "CARNET"; | ||
$allowedCardNetworks[4] = "CARTESBANCAIRES"; | ||
$allowedCardNetworks[5] = "CUP"; | ||
$allowedCardNetworks[6] = "DINERSCLUB"; | ||
$allowedCardNetworks[7] = "DISCOVER"; | ||
$allowedCardNetworks[8] = "EFTPOS"; | ||
$allowedCardNetworks[9] = "ELO"; | ||
$allowedCardNetworks[10] = "JCB"; | ||
$allowedCardNetworks[11] = "JCREW"; | ||
$allowedCardNetworks[12] = "MADA"; | ||
$allowedCardNetworks[13] = "MAESTRO"; | ||
$allowedCardNetworks[14] = "MEEZA"; | ||
$allowedPaymentTypes = array(); | ||
$allowedPaymentTypes[0] = "CLICKTOPAY"; | ||
$captureMandateShipToCountries = array(); | ||
$captureMandateShipToCountries[0] = "US"; | ||
$captureMandateShipToCountries[1] = "GB"; | ||
$captureMandateArr = [ | ||
"billingType" => "FULL", | ||
"requestEmail" => true, | ||
"requestPhone" => true, | ||
"requestShipping" => true, | ||
"shipToCountries" => $captureMandateShipToCountries, | ||
"showAcceptedNetworkIcons" => true | ||
]; | ||
$captureMandate = new CyberSource\Model\Upv1capturecontextsCaptureMandate($captureMandateArr); | ||
|
||
$orderInformationAmountDetailsArr = [ | ||
"totalAmount" => "21.00", | ||
"currency" => "USD" | ||
]; | ||
$orderInformationAmountDetails = new CyberSource\Model\Upv1capturecontextsOrderInformationAmountDetails($orderInformationAmountDetailsArr); | ||
|
||
$orderInformationArr = [ | ||
"amountDetails" => $orderInformationAmountDetails | ||
]; | ||
$orderInformation = new CyberSource\Model\Upv1capturecontextsOrderInformation($orderInformationArr); | ||
|
||
$requestObjArr = [ | ||
"clientVersion" => "0.23", | ||
"targetOrigins" => $targetOrigins, | ||
"allowedCardNetworks" => $allowedCardNetworks, | ||
"allowedPaymentTypes" => $allowedPaymentTypes, | ||
"country" => "US", | ||
"locale" => "en_US", | ||
"captureMandate" => $captureMandate, | ||
"orderInformation" => $orderInformation | ||
]; | ||
$requestObj = new CyberSource\Model\GenerateUnifiedCheckoutCaptureContextRequest($requestObjArr); | ||
|
||
|
||
$commonElement = new CyberSource\ExternalConfiguration(); | ||
$config = $commonElement->ConnectionHost(); | ||
$merchantConfig = $commonElement->merchantConfigObject(); | ||
|
||
$apiClient = new CyberSource\ApiClient($config, $merchantConfig); | ||
$apiInstance = new CyberSource\Api\UnifiedCheckoutCaptureContextApi($apiClient); | ||
|
||
try { | ||
$apiResponse = $apiInstance->generateUnifiedCheckoutCaptureContext($requestObj); | ||
print_r(PHP_EOL); | ||
print_r($apiResponse); | ||
|
||
return $apiResponse; | ||
} catch (Cybersource\ApiException $e) { | ||
print_r($e->getResponseBody()); | ||
print_r($e->getMessage()); | ||
} | ||
} | ||
|
||
if (!defined('DO_NOT_RUN_SAMPLES')) { | ||
echo "\GenerateCaptureContextForClickToPayDropInUI Sample Code is Running..." . PHP_EOL; | ||
GenerateCaptureContextForClickToPayDropInUI(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.