Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Follow up to #2907071: Add the configuration form..
Blocked by #2912356: Allow for altering requests in alterRequestParams.
Need to add a way to configure sandbox modes and execute them. See commerce_amazon_lpa_commerce_amazon_lpa_request_params_alter
/**
* Implements hook_commerce_amazon_lpa_request_params_alter().
*/
function commerce_amazon_lpa_commerce_amazon_lpa_request_params_alter(array &$params, $type, $data) {
// We must be in sandbox, and have simulation turned on to alter the params
// and set simulation messages.
$simulation_code = variable_get('commerce_amazon_lpa_simulation', '_none');
if (!AmazonLPA::is_sandbox() || $simulation_code == '_none') {
return;
}
// Do not run simulations during IPN.
if (isset($_SERVER['HTTP_X_AMZ_SNS_MESSAGE_TYPE'])) {
return;
}
switch ($type) {
case 'authorize':
switch ($simulation_code) {
case 'Authorizations_InvalidPaymentMethod':
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"InvalidPaymentMethod", "PaymentMethodUpdateTimeInMins":1}}';
break;
case 'Authorizations_AmazonRejected':
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
break;
case 'Authorizations_AmazonClosed':
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Closed", "ReasonCode":"AmazonClosed"}} ';
break;
case 'Authorizations_TransactionTimedOut':
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"TransactionTimedOut"}}';
break;
case 'Captures_Pending':
if (AmazonLPA::get_capture_mode() == AmazonLPA::CAPTURE_AUTH_CAPTURE) {
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Pending"}}';
}
break;
case 'Captures_AmazonRejected':
if (AmazonLPA::get_capture_mode() == AmazonLPA::CAPTURE_AUTH_CAPTURE) {
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
}
break;
case 'Captures_AmazonClosed':
if (AmazonLPA::get_capture_mode() == AmazonLPA::CAPTURE_AUTH_CAPTURE) {
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Closed", "ReasonCode":"AmazonClosed"}}';
}
break;
case 'Authorizations_ExpiredUnused':
$params['seller_authorization_note'] = '{"SandboxSimulation": {"State":"Closed", "ReasonCode":"ExpiredUnused", "ExpirationTimeInMins":1}}';
break;
}
break;
case 'cancel_order_reference':
break;
case 'capture':
switch ($simulation_code) {
case 'Captures_Pending':
$params['seller_capture_note'] = '{"SandboxSimulation": {"State":"Pending"}}';
break;
case 'Captures_AmazonRejected':
$params['seller_capture_note'] = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
break;
case 'Captures_AmazonClosed':
$params['seller_capture_note'] = '{"SandboxSimulation": {"State":"Closed", "ReasonCode":"AmazonClosed"}}';
break;
}
break;
case 'close_authorization':
break;
case 'close_order_reference':
switch ($simulation_code) {
case 'OrderReference_AmazonClosed':
$params['closure_reason'] = '{"SandboxSimulation": {"State":"Closed", "ReasonCode":"AmazonClosed"}}';
break;
}
break;
case 'confirm_order_reference':
break;
case 'get_capture_details':
break;
case 'get_order_reference':
break;
case 'refund':
switch ($simulation_code) {
case 'Refund_AmazonRejected':
$params['seller_refund_note'] = '{"SandboxSimulation": {"State":"Declined", "ReasonCode":"AmazonRejected"}}';
break;
}
break;
case 'set_order_reference':
break;
}
}
Comment | File | Size | Author |
---|---|---|---|
#7 | commerce_amazon_lpa-2909310-simulation_modes-6.patch | 6.49 KB | czigor |
|
Comments
Comment #2
mglamanComment #3
mglamanBlocked by #2912356: Allow for altering requests in alterRequestParams
Comment #4
mglamanFix issue summary.
Comment #5
mglamanJust add 7.,x code for easy reference.
Comment #6
czigor CreditAttribution: czigor at Centarro commentedThis is totally untested, still need to figure out how to make amazon pay work.
Comment #7
czigor CreditAttribution: czigor at Centarro commentedComment #9
mglamanThis works, however it has uncovered some logic handling bugs. Invalid payment methods are allowing checkout to continue.