Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Integrat.../Square/Api
File: Api.php
[1000] Fix | Delete
if ( ! $this->response instanceof ApiResponse ) {
[1001] Fix | Delete
return [];
[1002] Fix | Delete
}
[1003] Fix | Delete
[1004] Fix | Delete
$result = $this->response->getResult();
[1005] Fix | Delete
[1006] Fix | Delete
if ( $result instanceof CreatePaymentResponse ) {
[1007] Fix | Delete
return [ 'payment' => $this->response->getResult()->getPayment() ];
[1008] Fix | Delete
}
[1009] Fix | Delete
[1010] Fix | Delete
if ( $result instanceof CreateSubscriptionResponse || $result instanceof UpdateSubscriptionResponse ) {
[1011] Fix | Delete
return [ 'subscription' => $this->response->getResult()->getSubscription() ];
[1012] Fix | Delete
}
[1013] Fix | Delete
[1014] Fix | Delete
return [];
[1015] Fix | Delete
}
[1016] Fix | Delete
[1017] Fix | Delete
/**
[1018] Fix | Delete
* Retrieve last API call response and display error messages.
[1019] Fix | Delete
*
[1020] Fix | Delete
* @since 1.14.0
[1021] Fix | Delete
*
[1022] Fix | Delete
* @param string $type Type of error message.
[1023] Fix | Delete
*/
[1024] Fix | Delete
private function add_response_errors_message( string $type = 'API' ) {
[1025] Fix | Delete
[1026] Fix | Delete
$errors = $this->get_response_errors();
[1027] Fix | Delete
[1028] Fix | Delete
if ( empty( $errors ) ) {
[1029] Fix | Delete
return;
[1030] Fix | Delete
}
[1031] Fix | Delete
[1032] Fix | Delete
$key = ( $type === 'Exception' ) ? 'message' : 'detail';
[1033] Fix | Delete
[1034] Fix | Delete
foreach ( $errors as $error ) {
[1035] Fix | Delete
$message = $error[ $key ] ?? '';
[1036] Fix | Delete
[1037] Fix | Delete
if ( empty( $error['code'] ) || empty( $message ) ) {
[1038] Fix | Delete
return;
[1039] Fix | Delete
}
[1040] Fix | Delete
[1041] Fix | Delete
$this->errors[] = esc_html( $type ) . ': (' . esc_html( $error['code'] ) . ') ' . esc_html( $message );
[1042] Fix | Delete
}
[1043] Fix | Delete
}
[1044] Fix | Delete
[1045] Fix | Delete
/**
[1046] Fix | Delete
* Perform a subscription transaction.
[1047] Fix | Delete
*
[1048] Fix | Delete
* @since 1.9.5
[1049] Fix | Delete
*
[1050] Fix | Delete
* @param array $args Payment arguments.
[1051] Fix | Delete
*/
[1052] Fix | Delete
private function perform_subscription_transaction( array $args ) {
[1053] Fix | Delete
[1054] Fix | Delete
// Create a customer.
[1055] Fix | Delete
$customer_request = $this->prepare_create_customer_request( $args );
[1056] Fix | Delete
$customer = $this->send_create_customer_request( $customer_request );
[1057] Fix | Delete
[1058] Fix | Delete
if ( ! $customer instanceof Customer ) {
[1059] Fix | Delete
return;
[1060] Fix | Delete
}
[1061] Fix | Delete
[1062] Fix | Delete
// Create a customer card.
[1063] Fix | Delete
$card_request = $this->prepare_create_customer_card_request( $customer->getId(), $args );
[1064] Fix | Delete
$card = $this->send_create_customer_card_request( $card_request );
[1065] Fix | Delete
[1066] Fix | Delete
if ( ! $card instanceof Card ) {
[1067] Fix | Delete
return;
[1068] Fix | Delete
}
[1069] Fix | Delete
[1070] Fix | Delete
// Get a subscription plan.
[1071] Fix | Delete
$plan = $this->get_plan( $args );
[1072] Fix | Delete
[1073] Fix | Delete
if ( ! $plan instanceof CatalogObject ) {
[1074] Fix | Delete
return;
[1075] Fix | Delete
}
[1076] Fix | Delete
[1077] Fix | Delete
// Get a subscription plan variation.
[1078] Fix | Delete
$plan_variation = $this->get_plan_variation( $args, $plan );
[1079] Fix | Delete
[1080] Fix | Delete
if ( ! $plan_variation instanceof CatalogObject ) {
[1081] Fix | Delete
return;
[1082] Fix | Delete
}
[1083] Fix | Delete
[1084] Fix | Delete
// Create a subscription.
[1085] Fix | Delete
$subscription_request = $this->prepare_create_subscription_request( $plan_variation->getId(), $customer->getId(), $card->getId(), $args );
[1086] Fix | Delete
[1087] Fix | Delete
$this->send_create_subscription_request( $subscription_request );
[1088] Fix | Delete
}
[1089] Fix | Delete
[1090] Fix | Delete
/**
[1091] Fix | Delete
* Check if all required subscription arguments are present.
[1092] Fix | Delete
*
[1093] Fix | Delete
* @since 1.9.5
[1094] Fix | Delete
*
[1095] Fix | Delete
* @param array $args Arguments to check.
[1096] Fix | Delete
*/
[1097] Fix | Delete
private function check_required_args_subscription( array $args ) {
[1098] Fix | Delete
[1099] Fix | Delete
if ( empty( $args['subscription']['plan_name'] ) ) {
[1100] Fix | Delete
$this->errors[] = esc_html__( 'Missing subscription plan name.', 'wpforms-lite' );
[1101] Fix | Delete
}
[1102] Fix | Delete
[1103] Fix | Delete
if ( empty( $args['subscription']['plan_variation_name'] ) ) {
[1104] Fix | Delete
$this->errors[] = esc_html__( 'Missing subscription plan variation name.', 'wpforms-lite' );
[1105] Fix | Delete
}
[1106] Fix | Delete
[1107] Fix | Delete
if ( empty( $args['subscription']['phase_cadence'] ) ) {
[1108] Fix | Delete
$this->errors[] = esc_html__( 'Missing subscription cadence.', 'wpforms-lite' );
[1109] Fix | Delete
}
[1110] Fix | Delete
[1111] Fix | Delete
if ( empty( $args['subscription']['customer']['first_name'] ) && empty( $args['subscription']['customer']['last_name'] ) ) {
[1112] Fix | Delete
$this->errors[] = esc_html__( 'Missing customer name.', 'wpforms-lite' );
[1113] Fix | Delete
}
[1114] Fix | Delete
[1115] Fix | Delete
if ( empty( $args['subscription']['customer']['email'] ) ) {
[1116] Fix | Delete
$this->errors[] = esc_html__( 'Missing customer email.', 'wpforms-lite' );
[1117] Fix | Delete
}
[1118] Fix | Delete
}
[1119] Fix | Delete
[1120] Fix | Delete
/**
[1121] Fix | Delete
* Prepare a create customer request object for sending to API.
[1122] Fix | Delete
*
[1123] Fix | Delete
* @since 1.9.5
[1124] Fix | Delete
*
[1125] Fix | Delete
* @param array $args Payment arguments.
[1126] Fix | Delete
*
[1127] Fix | Delete
* @return CreateCustomerRequest
[1128] Fix | Delete
*/
[1129] Fix | Delete
private function prepare_create_customer_request( array $args ): CreateCustomerRequest {
[1130] Fix | Delete
[1131] Fix | Delete
$request = $this->get_create_customer_request_object();
[1132] Fix | Delete
[1133] Fix | Delete
$request->setEmailAddress( $args['subscription']['customer']['email'] );
[1134] Fix | Delete
[1135] Fix | Delete
if ( ! empty( $args['subscription']['customer']['first_name'] ) ) {
[1136] Fix | Delete
$request->setGivenName( $args['subscription']['customer']['first_name'] );
[1137] Fix | Delete
}
[1138] Fix | Delete
[1139] Fix | Delete
if ( ! empty( $args['subscription']['customer']['last_name'] ) ) {
[1140] Fix | Delete
$request->setFamilyName( $args['subscription']['customer']['last_name'] );
[1141] Fix | Delete
}
[1142] Fix | Delete
[1143] Fix | Delete
if ( ! empty( $args['subscription']['customer']['address'] ) ) {
[1144] Fix | Delete
$address = $this->get_address_object( $args['subscription']['customer'] );
[1145] Fix | Delete
[1146] Fix | Delete
$request->setAddress( $address );
[1147] Fix | Delete
}
[1148] Fix | Delete
[1149] Fix | Delete
return $request;
[1150] Fix | Delete
}
[1151] Fix | Delete
[1152] Fix | Delete
/**
[1153] Fix | Delete
* Prepare a create customer card request object for sending to API.
[1154] Fix | Delete
*
[1155] Fix | Delete
* @since 1.9.5
[1156] Fix | Delete
*
[1157] Fix | Delete
* @param string $customer_id Customer ID.
[1158] Fix | Delete
* @param array $args Payment arguments.
[1159] Fix | Delete
*
[1160] Fix | Delete
* @return CreateCardRequest
[1161] Fix | Delete
*/
[1162] Fix | Delete
private function prepare_create_customer_card_request( string $customer_id, array $args ): CreateCardRequest {
[1163] Fix | Delete
[1164] Fix | Delete
$request = new CreateCardRequest( $this->get_idempotency_key(), $this->source_id, new Card() );
[1165] Fix | Delete
[1166] Fix | Delete
$request->getCard()->setCustomerId( $customer_id );
[1167] Fix | Delete
[1168] Fix | Delete
if ( ! empty( $args['subscription']['customer']['address'] ) ) {
[1169] Fix | Delete
$address = $this->get_address_object( $args['subscription']['customer'] );
[1170] Fix | Delete
[1171] Fix | Delete
// For subscriptions: make sure that a postal code is not empty.
[1172] Fix | Delete
// Otherwise, API error "The postal code doesn't match the one used for card nonce creation" is occur here.
[1173] Fix | Delete
if ( ! empty( $address->getPostalCode() ) ) {
[1174] Fix | Delete
$request->getCard()->setBillingAddress( $address );
[1175] Fix | Delete
}
[1176] Fix | Delete
}
[1177] Fix | Delete
[1178] Fix | Delete
if ( ! empty( $args['subscription']['card_name'] ) ) {
[1179] Fix | Delete
$request->getCard()->setCardholderName( $args['subscription']['card_name'] );
[1180] Fix | Delete
}
[1181] Fix | Delete
[1182] Fix | Delete
return $request;
[1183] Fix | Delete
}
[1184] Fix | Delete
[1185] Fix | Delete
/**
[1186] Fix | Delete
* Prepare a create subscription request object for sending to API.
[1187] Fix | Delete
*
[1188] Fix | Delete
* @since 1.9.5
[1189] Fix | Delete
*
[1190] Fix | Delete
* @param string $plan_id Plan ID.
[1191] Fix | Delete
* @param string $customer_id Customer ID.
[1192] Fix | Delete
* @param string $card_id Customer ID.
[1193] Fix | Delete
* @param array $args Payment arguments.
[1194] Fix | Delete
*
[1195] Fix | Delete
* @return CreateSubscriptionRequest
[1196] Fix | Delete
*/
[1197] Fix | Delete
private function prepare_create_subscription_request( string $plan_id, string $customer_id, string $card_id, array $args ): CreateSubscriptionRequest {
[1198] Fix | Delete
[1199] Fix | Delete
$request = $this->get_create_subscription_request_object( $plan_id, $customer_id, $args );
[1200] Fix | Delete
[1201] Fix | Delete
$request->setCardId( $card_id );
[1202] Fix | Delete
$request->setSource( new SubscriptionSource() );
[1203] Fix | Delete
$request->getSource()->setName( Square::APP_NAME );
[1204] Fix | Delete
[1205] Fix | Delete
return $request;
[1206] Fix | Delete
}
[1207] Fix | Delete
[1208] Fix | Delete
/**
[1209] Fix | Delete
* Retrieve a create customer request object.
[1210] Fix | Delete
*
[1211] Fix | Delete
* @since 1.9.5
[1212] Fix | Delete
*
[1213] Fix | Delete
* @return CreateCustomerRequest
[1214] Fix | Delete
*/
[1215] Fix | Delete
private function get_create_customer_request_object(): CreateCustomerRequest {
[1216] Fix | Delete
[1217] Fix | Delete
$request = new CreateCustomerRequest();
[1218] Fix | Delete
[1219] Fix | Delete
$request->setIdempotencyKey( $this->get_idempotency_key() );
[1220] Fix | Delete
[1221] Fix | Delete
return $request;
[1222] Fix | Delete
}
[1223] Fix | Delete
[1224] Fix | Delete
/**
[1225] Fix | Delete
* Retrieve a search catalog request object.
[1226] Fix | Delete
*
[1227] Fix | Delete
* @since 1.9.5
[1228] Fix | Delete
*
[1229] Fix | Delete
* @param string $type Object type.
[1230] Fix | Delete
* @param string $name Object name.
[1231] Fix | Delete
*
[1232] Fix | Delete
* @return SearchCatalogObjectsRequest
[1233] Fix | Delete
*/
[1234] Fix | Delete
private function get_search_catalog_request_object( string $type, string $name ): SearchCatalogObjectsRequest {
[1235] Fix | Delete
[1236] Fix | Delete
$request = new SearchCatalogObjectsRequest();
[1237] Fix | Delete
[1238] Fix | Delete
$request->setObjectTypes( [ $type ] );
[1239] Fix | Delete
$request->setLimit( 1 );
[1240] Fix | Delete
$request->setQuery( new CatalogQuery() );
[1241] Fix | Delete
$request->getQuery()->setExactQuery( new CatalogQueryExact( 'name', $name ) );
[1242] Fix | Delete
[1243] Fix | Delete
return $request;
[1244] Fix | Delete
}
[1245] Fix | Delete
[1246] Fix | Delete
/**
[1247] Fix | Delete
* Retrieve a create plan request object.
[1248] Fix | Delete
*
[1249] Fix | Delete
* @since 1.9.5
[1250] Fix | Delete
*
[1251] Fix | Delete
* @param array $args Payment arguments.
[1252] Fix | Delete
*
[1253] Fix | Delete
* @return UpsertCatalogObjectRequest
[1254] Fix | Delete
*/
[1255] Fix | Delete
private function get_create_plan_request_object( array $args ): UpsertCatalogObjectRequest {
[1256] Fix | Delete
[1257] Fix | Delete
$request = new UpsertCatalogObjectRequest( $this->get_idempotency_key(), new CatalogObject( CatalogObjectType::SUBSCRIPTION_PLAN, '#plan' ) );
[1258] Fix | Delete
[1259] Fix | Delete
$plan_data = new CatalogSubscriptionPlan( $args['subscription']['plan_name'] );
[1260] Fix | Delete
[1261] Fix | Delete
$plan_data->setAllItems( true );
[1262] Fix | Delete
[1263] Fix | Delete
$request->getObject()->setSubscriptionPlanData( $plan_data );
[1264] Fix | Delete
[1265] Fix | Delete
return $request;
[1266] Fix | Delete
}
[1267] Fix | Delete
[1268] Fix | Delete
/**
[1269] Fix | Delete
* Get subscription plan variation.
[1270] Fix | Delete
*
[1271] Fix | Delete
* @since 1.9.5
[1272] Fix | Delete
*
[1273] Fix | Delete
* @param array $args Payment arguments.
[1274] Fix | Delete
* @param CatalogObject $plan Plan object.
[1275] Fix | Delete
*
[1276] Fix | Delete
* @return CatalogObject|null
[1277] Fix | Delete
*/
[1278] Fix | Delete
private function get_plan_variation( array $args, $plan ) {
[1279] Fix | Delete
[1280] Fix | Delete
// Search a subscription plan.
[1281] Fix | Delete
$search_plan_request = $this->get_search_catalog_request_object( CatalogObjectType::SUBSCRIPTION_PLAN_VARIATION, $args['subscription']['plan_name'] );
[1282] Fix | Delete
$plan_variation = $this->send_search_catalog_request( $search_plan_request );
[1283] Fix | Delete
[1284] Fix | Delete
// Create a subscription plan if it's not exists.
[1285] Fix | Delete
if ( $plan_variation !== null ) {
[1286] Fix | Delete
return $plan_variation;
[1287] Fix | Delete
}
[1288] Fix | Delete
[1289] Fix | Delete
$plan_variations_request = $this->get_create_plan_variations_request_object( $args, $plan );
[1290] Fix | Delete
$plan_variation = $this->send_create_plan_variations_request( $plan_variations_request );
[1291] Fix | Delete
[1292] Fix | Delete
if ( ! $plan_variation instanceof CatalogObject ) {
[1293] Fix | Delete
return null;
[1294] Fix | Delete
}
[1295] Fix | Delete
[1296] Fix | Delete
return $plan_variation;
[1297] Fix | Delete
}
[1298] Fix | Delete
[1299] Fix | Delete
/**
[1300] Fix | Delete
* Retrieve a create plan variation request object.
[1301] Fix | Delete
*
[1302] Fix | Delete
* @since 1.9.5
[1303] Fix | Delete
*
[1304] Fix | Delete
* @param array $args Payment arguments.
[1305] Fix | Delete
* @param CatalogObject $plan Plan object.
[1306] Fix | Delete
*
[1307] Fix | Delete
* @return UpsertCatalogObjectRequest
[1308] Fix | Delete
*/
[1309] Fix | Delete
private function get_create_plan_variations_request_object( array $args, $plan ): UpsertCatalogObjectRequest {
[1310] Fix | Delete
[1311] Fix | Delete
$request = new UpsertCatalogObjectRequest( $this->get_idempotency_key(), new CatalogObject( CatalogObjectType::SUBSCRIPTION_PLAN_VARIATION, '#plan_variation' ) );
[1312] Fix | Delete
[1313] Fix | Delete
$phase = new SubscriptionPhase( $args['subscription']['phase_cadence']['value'] );
[1314] Fix | Delete
[1315] Fix | Delete
$phase->setPricing( new SubscriptionPricing() );
[1316] Fix | Delete
$phase->getPricing()->setType( 'STATIC' );
[1317] Fix | Delete
$phase->getPricing()->setPriceMoney( new Money() );
[1318] Fix | Delete
$phase->getPricing()->getPriceMoney()->setAmount( $args['amount'] );
[1319] Fix | Delete
$phase->getPricing()->getPriceMoney()->setCurrency( $args['currency'] );
[1320] Fix | Delete
[1321] Fix | Delete
$request->getObject()->setSubscriptionPlanVariationData( new CatalogSubscriptionPlanVariation( $args['subscription']['plan_variation_name'], [ $phase ] ) );
[1322] Fix | Delete
$request->getObject()->getSubscriptionPlanVariationData()->setSubscriptionPlanId( $plan->getId() );
[1323] Fix | Delete
[1324] Fix | Delete
return $request;
[1325] Fix | Delete
}
[1326] Fix | Delete
[1327] Fix | Delete
/**
[1328] Fix | Delete
* Retrieve a create subscription request object.
[1329] Fix | Delete
*
[1330] Fix | Delete
* @since 1.9.5
[1331] Fix | Delete
*
[1332] Fix | Delete
* @param string $plan_id Plan ID.
[1333] Fix | Delete
* @param string $customer_id Customer ID.
[1334] Fix | Delete
* @param array $args Payment arguments.
[1335] Fix | Delete
*
[1336] Fix | Delete
* @return CreateSubscriptionRequest
[1337] Fix | Delete
*/
[1338] Fix | Delete
private function get_create_subscription_request_object( string $plan_id, string $customer_id, array $args ): CreateSubscriptionRequest {
[1339] Fix | Delete
[1340] Fix | Delete
$request = new CreateSubscriptionRequest( $args['location_id'], $customer_id );
[1341] Fix | Delete
[1342] Fix | Delete
$request->setIdempotencyKey( $this->get_idempotency_key() );
[1343] Fix | Delete
$request->setPlanVariationId( $plan_id );
[1344] Fix | Delete
[1345] Fix | Delete
return $request;
[1346] Fix | Delete
}
[1347] Fix | Delete
[1348] Fix | Delete
/**
[1349] Fix | Delete
* Send a create customer request to API.
[1350] Fix | Delete
*
[1351] Fix | Delete
* @since 1.9.5
[1352] Fix | Delete
*
[1353] Fix | Delete
* @param CreateCustomerRequest $request Create customer request object.
[1354] Fix | Delete
*
[1355] Fix | Delete
* @return Customer|null
[1356] Fix | Delete
*/
[1357] Fix | Delete
private function send_create_customer_request( $request ) {
[1358] Fix | Delete
[1359] Fix | Delete
try {
[1360] Fix | Delete
$this->response = $this->client->getCustomersApi()->createCustomer( $request );
[1361] Fix | Delete
[1362] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1363] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: customer was not created.', 'wpforms-lite' );
[1364] Fix | Delete
[1365] Fix | Delete
return null;
[1366] Fix | Delete
}
[1367] Fix | Delete
[1368] Fix | Delete
return $this->response->getResult()->getCustomer();
[1369] Fix | Delete
[1370] Fix | Delete
} catch ( ApiException $e ) {
[1371] Fix | Delete
$this->exception = $e;
[1372] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: customer was not created.', 'wpforms-lite' );
[1373] Fix | Delete
[1374] Fix | Delete
return null;
[1375] Fix | Delete
}
[1376] Fix | Delete
}
[1377] Fix | Delete
[1378] Fix | Delete
/**
[1379] Fix | Delete
* Send a retrieve card request to API.
[1380] Fix | Delete
*
[1381] Fix | Delete
* @since 1.9.5
[1382] Fix | Delete
*
[1383] Fix | Delete
* @param string $id The ID of the customer to retrieve.
[1384] Fix | Delete
*
[1385] Fix | Delete
* @return Card|null
[1386] Fix | Delete
*/
[1387] Fix | Delete
private function send_retrieve_card_request( string $id ) {
[1388] Fix | Delete
[1389] Fix | Delete
try {
[1390] Fix | Delete
$response = $this->client->getCardsApi()->retrieveCard( $id );
[1391] Fix | Delete
[1392] Fix | Delete
if ( ! $response->isSuccess() ) {
[1393] Fix | Delete
return null;
[1394] Fix | Delete
}
[1395] Fix | Delete
[1396] Fix | Delete
return $response->getResult()->getCard();
[1397] Fix | Delete
[1398] Fix | Delete
} catch ( ApiException $e ) {
[1399] Fix | Delete
return null;
[1400] Fix | Delete
}
[1401] Fix | Delete
}
[1402] Fix | Delete
[1403] Fix | Delete
/**
[1404] Fix | Delete
* Send a create customer card request to API.
[1405] Fix | Delete
*
[1406] Fix | Delete
* @since 1.9.5
[1407] Fix | Delete
*
[1408] Fix | Delete
* @param CreateCardRequest $request Create card request object.
[1409] Fix | Delete
*
[1410] Fix | Delete
* @return Card|null
[1411] Fix | Delete
*/
[1412] Fix | Delete
private function send_create_customer_card_request( $request ) {
[1413] Fix | Delete
[1414] Fix | Delete
try {
[1415] Fix | Delete
$this->response = $this->client->getCardsApi()->createCard( $request );
[1416] Fix | Delete
[1417] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1418] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: customer card was not created.', 'wpforms-lite' );
[1419] Fix | Delete
[1420] Fix | Delete
return null;
[1421] Fix | Delete
}
[1422] Fix | Delete
[1423] Fix | Delete
return $this->response->getResult()->getCard();
[1424] Fix | Delete
[1425] Fix | Delete
} catch ( ApiException $e ) {
[1426] Fix | Delete
$this->exception = $e;
[1427] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: customer card was not created.', 'wpforms-lite' );
[1428] Fix | Delete
[1429] Fix | Delete
return null;
[1430] Fix | Delete
}
[1431] Fix | Delete
}
[1432] Fix | Delete
[1433] Fix | Delete
/**
[1434] Fix | Delete
* Send a search catalog request to API.
[1435] Fix | Delete
*
[1436] Fix | Delete
* @since 1.9.5
[1437] Fix | Delete
*
[1438] Fix | Delete
* @param SearchCatalogObjectsRequest $request Search subscription plan request object.
[1439] Fix | Delete
*
[1440] Fix | Delete
* @return CatalogObject|null
[1441] Fix | Delete
*/
[1442] Fix | Delete
private function send_search_catalog_request( $request ) {
[1443] Fix | Delete
[1444] Fix | Delete
try {
[1445] Fix | Delete
$this->response = $this->client->getCatalogApi()->searchCatalogObjects( $request );
[1446] Fix | Delete
[1447] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1448] Fix | Delete
return null;
[1449] Fix | Delete
}
[1450] Fix | Delete
[1451] Fix | Delete
$objects = $this->response->getResult()->getObjects();
[1452] Fix | Delete
[1453] Fix | Delete
if ( ! is_array( $objects ) || empty( $objects[0] ) ) {
[1454] Fix | Delete
return null;
[1455] Fix | Delete
}
[1456] Fix | Delete
[1457] Fix | Delete
return $objects[0];
[1458] Fix | Delete
[1459] Fix | Delete
} catch ( ApiException $e ) {
[1460] Fix | Delete
$this->exception = $e;
[1461] Fix | Delete
[1462] Fix | Delete
return null;
[1463] Fix | Delete
}
[1464] Fix | Delete
}
[1465] Fix | Delete
[1466] Fix | Delete
/**
[1467] Fix | Delete
* Get subscription plan.
[1468] Fix | Delete
*
[1469] Fix | Delete
* @since 1.9.5
[1470] Fix | Delete
*
[1471] Fix | Delete
* @param array $args Payment arguments.
[1472] Fix | Delete
*
[1473] Fix | Delete
* @return CatalogObject|null
[1474] Fix | Delete
*/
[1475] Fix | Delete
private function get_plan( array $args ) {
[1476] Fix | Delete
[1477] Fix | Delete
// Search a subscription plan.
[1478] Fix | Delete
$search_plan_request = $this->get_search_catalog_request_object( CatalogObjectType::SUBSCRIPTION_PLAN, $args['subscription']['plan_variation_name'] );
[1479] Fix | Delete
$plan = $this->send_search_catalog_request( $search_plan_request );
[1480] Fix | Delete
[1481] Fix | Delete
// Create a subscription plan if it's not exists.
[1482] Fix | Delete
if ( $plan === null ) {
[1483] Fix | Delete
$create_plan_request = $this->get_create_plan_request_object( $args );
[1484] Fix | Delete
$plan = $this->send_create_plan_request( $create_plan_request );
[1485] Fix | Delete
}
[1486] Fix | Delete
[1487] Fix | Delete
if ( ! $plan instanceof CatalogObject ) {
[1488] Fix | Delete
return null;
[1489] Fix | Delete
}
[1490] Fix | Delete
[1491] Fix | Delete
return $plan;
[1492] Fix | Delete
}
[1493] Fix | Delete
[1494] Fix | Delete
/**
[1495] Fix | Delete
* Send a create subscription plan request to API.
[1496] Fix | Delete
*
[1497] Fix | Delete
* @since 1.9.5
[1498] Fix | Delete
*
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function