Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/wpforms-.../src/Integrat.../Square/Api
File: Api.php
* @param UpsertCatalogObjectRequest $request Create subscription plan request object.
[1500] Fix | Delete
*
[1501] Fix | Delete
* @return CatalogObject|null
[1502] Fix | Delete
*/
[1503] Fix | Delete
private function send_create_plan_request( $request ) {
[1504] Fix | Delete
[1505] Fix | Delete
try {
[1506] Fix | Delete
$this->response = $this->client->getCatalogApi()->upsertCatalogObject( $request );
[1507] Fix | Delete
[1508] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1509] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: subscription plan was not created.', 'wpforms-lite' );
[1510] Fix | Delete
[1511] Fix | Delete
return null;
[1512] Fix | Delete
}
[1513] Fix | Delete
[1514] Fix | Delete
return $this->response->getResult()->getCatalogObject();
[1515] Fix | Delete
[1516] Fix | Delete
} catch ( ApiException $e ) {
[1517] Fix | Delete
$this->exception = $e;
[1518] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: subscription plan was not created.', 'wpforms-lite' );
[1519] Fix | Delete
[1520] Fix | Delete
return null;
[1521] Fix | Delete
}
[1522] Fix | Delete
}
[1523] Fix | Delete
[1524] Fix | Delete
/**
[1525] Fix | Delete
* Send a create subscription plan variations request to API.
[1526] Fix | Delete
*
[1527] Fix | Delete
* @since 1.9.5
[1528] Fix | Delete
*
[1529] Fix | Delete
* @param UpsertCatalogObjectRequest $request Create subscription plan request object.
[1530] Fix | Delete
*
[1531] Fix | Delete
* @return CatalogObject|null
[1532] Fix | Delete
*/
[1533] Fix | Delete
private function send_create_plan_variations_request( $request ) {
[1534] Fix | Delete
[1535] Fix | Delete
try {
[1536] Fix | Delete
$this->response = $this->client->getCatalogApi()->upsertCatalogObject( $request );
[1537] Fix | Delete
[1538] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1539] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: subscription plan variation was not created.', 'wpforms-lite' );
[1540] Fix | Delete
[1541] Fix | Delete
return null;
[1542] Fix | Delete
}
[1543] Fix | Delete
[1544] Fix | Delete
return $this->response->getResult()->getCatalogObject();
[1545] Fix | Delete
[1546] Fix | Delete
} catch ( ApiException $e ) {
[1547] Fix | Delete
$this->exception = $e;
[1548] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: subscription plan variation was not created.', 'wpforms-lite' );
[1549] Fix | Delete
[1550] Fix | Delete
return null;
[1551] Fix | Delete
}
[1552] Fix | Delete
}
[1553] Fix | Delete
[1554] Fix | Delete
/**
[1555] Fix | Delete
* Send a create subscription request to API.
[1556] Fix | Delete
*
[1557] Fix | Delete
* @since 1.9.5
[1558] Fix | Delete
*
[1559] Fix | Delete
* @param CreateSubscriptionRequest $request Create subscription request object.
[1560] Fix | Delete
*
[1561] Fix | Delete
* @return Subscription|null
[1562] Fix | Delete
*/
[1563] Fix | Delete
private function send_create_subscription_request( $request ) {
[1564] Fix | Delete
[1565] Fix | Delete
try {
[1566] Fix | Delete
$this->response = $this->client->getSubscriptionsApi()->createSubscription( $request );
[1567] Fix | Delete
[1568] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1569] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: something went wrong during subscription process.', 'wpforms-lite' );
[1570] Fix | Delete
[1571] Fix | Delete
return null;
[1572] Fix | Delete
}
[1573] Fix | Delete
[1574] Fix | Delete
return $this->response->getResult()->getSubscription();
[1575] Fix | Delete
[1576] Fix | Delete
} catch ( ApiException $e ) {
[1577] Fix | Delete
$this->exception = $e;
[1578] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: something went wrong during subscription process.', 'wpforms-lite' );
[1579] Fix | Delete
[1580] Fix | Delete
return null;
[1581] Fix | Delete
}
[1582] Fix | Delete
}
[1583] Fix | Delete
[1584] Fix | Delete
/**
[1585] Fix | Delete
* Retrieve a update subscription request object.
[1586] Fix | Delete
*
[1587] Fix | Delete
* @since 1.9.5
[1588] Fix | Delete
*
[1589] Fix | Delete
* @param Subscription $subscription Subscription object.
[1590] Fix | Delete
* @param array $args Subscription arguments.
[1591] Fix | Delete
*
[1592] Fix | Delete
* @return UpdateSubscriptionRequest|null
[1593] Fix | Delete
*/
[1594] Fix | Delete
private function get_update_subscription_request_object( $subscription, array $args ) {
[1595] Fix | Delete
[1596] Fix | Delete
if ( ! $subscription instanceof Subscription ) {
[1597] Fix | Delete
return null;
[1598] Fix | Delete
}
[1599] Fix | Delete
[1600] Fix | Delete
$subscription->setSource( new SubscriptionSource() );
[1601] Fix | Delete
$subscription->getSource()->setName( Square::APP_NAME . ' Payment #' . $args['payment_id'] );
[1602] Fix | Delete
[1603] Fix | Delete
$request = new UpdateSubscriptionRequest();
[1604] Fix | Delete
[1605] Fix | Delete
$request->setSubscription( $subscription );
[1606] Fix | Delete
[1607] Fix | Delete
return $request;
[1608] Fix | Delete
}
[1609] Fix | Delete
[1610] Fix | Delete
/**
[1611] Fix | Delete
* Send a create subscription request to API.
[1612] Fix | Delete
*
[1613] Fix | Delete
* @since 1.9.5
[1614] Fix | Delete
*
[1615] Fix | Delete
* @param string $subscription_id Subscription id.
[1616] Fix | Delete
* @param UpdateSubscriptionRequest $request Update subscription request object.
[1617] Fix | Delete
*
[1618] Fix | Delete
* @return Subscription|null
[1619] Fix | Delete
*/
[1620] Fix | Delete
private function send_update_subscription_request( string $subscription_id, $request ) {
[1621] Fix | Delete
[1622] Fix | Delete
try {
[1623] Fix | Delete
$this->response = $this->client->getSubscriptionsApi()->updateSubscription( $subscription_id, $request );
[1624] Fix | Delete
[1625] Fix | Delete
if ( ! $this->response->isSuccess() ) {
[1626] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: something went wrong during subscription update.', 'wpforms-lite' );
[1627] Fix | Delete
[1628] Fix | Delete
return null;
[1629] Fix | Delete
}
[1630] Fix | Delete
[1631] Fix | Delete
return $this->response->getResult()->getSubscription();
[1632] Fix | Delete
[1633] Fix | Delete
} catch ( ApiException $e ) {
[1634] Fix | Delete
$this->exception = $e;
[1635] Fix | Delete
$this->errors[] = esc_html__( 'Square fail: something went wrong during subscription update.', 'wpforms-lite' );
[1636] Fix | Delete
[1637] Fix | Delete
return null;
[1638] Fix | Delete
}
[1639] Fix | Delete
}
[1640] Fix | Delete
[1641] Fix | Delete
/**
[1642] Fix | Delete
* Retrieve card details from specific transaction in object format.
[1643] Fix | Delete
*
[1644] Fix | Delete
* @since 1.9.5
[1645] Fix | Delete
*
[1646] Fix | Delete
* @param string $transaction_id The ID of the order to retrieve card details from.
[1647] Fix | Delete
*
[1648] Fix | Delete
* @return stdClass|void
[1649] Fix | Delete
*/
[1650] Fix | Delete
public function get_card_details_from_transaction_id( string $transaction_id ) {
[1651] Fix | Delete
[1652] Fix | Delete
$response = $this->client->getPaymentsApi()->getPayment( $transaction_id );
[1653] Fix | Delete
[1654] Fix | Delete
if ( ! $response->isSuccess() ) {
[1655] Fix | Delete
return;
[1656] Fix | Delete
}
[1657] Fix | Delete
[1658] Fix | Delete
$payment = $response->getResult()->getPayment();
[1659] Fix | Delete
$card_details = $payment->getCardDetails();
[1660] Fix | Delete
[1661] Fix | Delete
if ( ! $card_details ) {
[1662] Fix | Delete
return;
[1663] Fix | Delete
}
[1664] Fix | Delete
[1665] Fix | Delete
$card = $card_details->getCard();
[1666] Fix | Delete
[1667] Fix | Delete
if ( ! $card ) {
[1668] Fix | Delete
return;
[1669] Fix | Delete
}
[1670] Fix | Delete
[1671] Fix | Delete
// Create a temporary object to mimic Square's payment_method_details structure.
[1672] Fix | Delete
$details = new stdClass();
[1673] Fix | Delete
$details->source_type = 'card';
[1674] Fix | Delete
$details->card_details = new stdClass();
[1675] Fix | Delete
$details->card_details->card = new stdClass();
[1676] Fix | Delete
$details->card_details->card->last_4 = $card->getLast4();
[1677] Fix | Delete
$details->card_details->card->card_brand = $card->getCardBrand();
[1678] Fix | Delete
$details->card_details->card->exp_month = $card->getExpMonth();
[1679] Fix | Delete
$details->card_details->card->exp_year = $card->getExpYear();
[1680] Fix | Delete
[1681] Fix | Delete
return $details;
[1682] Fix | Delete
}
[1683] Fix | Delete
[1684] Fix | Delete
/**
[1685] Fix | Delete
* Retrieve the latest invoice transaction_id.
[1686] Fix | Delete
*
[1687] Fix | Delete
* @since 1.9.5
[1688] Fix | Delete
*
[1689] Fix | Delete
* @param Invoice $invoice Invoice object.
[1690] Fix | Delete
*
[1691] Fix | Delete
* @return string
[1692] Fix | Delete
*/
[1693] Fix | Delete
public function get_latest_invoice_transaction_id( $invoice ): string {
[1694] Fix | Delete
[1695] Fix | Delete
$order_id = $invoice->getOrderId();
[1696] Fix | Delete
[1697] Fix | Delete
if ( ! $order_id ) {
[1698] Fix | Delete
return '';
[1699] Fix | Delete
}
[1700] Fix | Delete
[1701] Fix | Delete
$order_response = $this->client->getOrdersApi()->retrieveOrder( $order_id );
[1702] Fix | Delete
[1703] Fix | Delete
if ( ! $order_response->isSuccess() ) {
[1704] Fix | Delete
return '';
[1705] Fix | Delete
}
[1706] Fix | Delete
[1707] Fix | Delete
$order = $order_response->getResult()->getOrder();
[1708] Fix | Delete
$tenders = $order->getTenders();
[1709] Fix | Delete
[1710] Fix | Delete
if ( empty( $tenders ) ) {
[1711] Fix | Delete
return '';
[1712] Fix | Delete
}
[1713] Fix | Delete
[1714] Fix | Delete
// Assuming the last tender represents the final transaction.
[1715] Fix | Delete
return end( $tenders )->getPaymentId();
[1716] Fix | Delete
}
[1717] Fix | Delete
[1718] Fix | Delete
/**
[1719] Fix | Delete
* Retrieve the invoice by order ID.
[1720] Fix | Delete
*
[1721] Fix | Delete
* @since 1.9.5
[1722] Fix | Delete
*
[1723] Fix | Delete
* @param string $order_id Order ID.
[1724] Fix | Delete
*
[1725] Fix | Delete
* @return Invoice|null
[1726] Fix | Delete
*/
[1727] Fix | Delete
public function get_invoice_by_order_id( string $order_id ) {
[1728] Fix | Delete
[1729] Fix | Delete
$invoices_api = $this->client->getInvoicesApi();
[1730] Fix | Delete
[1731] Fix | Delete
try {
[1732] Fix | Delete
$response = $invoices_api->listInvoices( Helpers::get_location_id() );
[1733] Fix | Delete
[1734] Fix | Delete
if ( ! $response->isSuccess() ) {
[1735] Fix | Delete
return null;
[1736] Fix | Delete
}
[1737] Fix | Delete
[1738] Fix | Delete
$invoices = $response->getResult()->getInvoices();
[1739] Fix | Delete
[1740] Fix | Delete
if ( empty( $invoices ) ) {
[1741] Fix | Delete
return null;
[1742] Fix | Delete
}
[1743] Fix | Delete
[1744] Fix | Delete
foreach ( $invoices as $invoice ) {
[1745] Fix | Delete
if ( $invoice->getOrderId() === $order_id ) {
[1746] Fix | Delete
return $invoice;
[1747] Fix | Delete
}
[1748] Fix | Delete
}
[1749] Fix | Delete
} catch ( ApiException $e ) {
[1750] Fix | Delete
return null;
[1751] Fix | Delete
}
[1752] Fix | Delete
[1753] Fix | Delete
return null;
[1754] Fix | Delete
}
[1755] Fix | Delete
}
[1756] Fix | Delete
[1757] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function