Credit card number is garbled when testing Stripe.js in Mink - testing

I am trying to use Behat/Mink to test Stripe on my Drupal site.
I have a Stripe testing payment gateway configured. My
My FeatureContext.php looks like this:
/**
* #Then I enter my US JCB credit card info
*/
public function iEnterMyUsJcbCreditCardInfo() {
$this->enterCardDetails('3566 0020 2036 0505', '11 / 21', '777');
}
private function enterCardDetails($card_number, $exp_date, $cvc) {
$this->getSession()->wait(2000);
// Switch to the payment iframe.
$this->getSession()->switchToIFrame(self::STRIPE_CARDNO_IFRAME);
$this->getSession()->wait(1000);
$this->fillField('cardnumber', "$card_number");
$this->getSession()->wait(2000);
I added the wait() because the credit card number is being filled out incorrectly.
For example, when I have the step And I enter my US JCB credit card info, then instead of the correct test card number (3566 0020 2036 0505), I get this: 3566 0000 3605 5022.
The incorrect card number is not consistent; when I re-ran the test three times, I got these numbers:
3566 0022 3005 5600
3566 0002 0360 5502
3566 0006 5500 3220
So it seems like something with stripe.js is interfering with my credit card number input.
The credit card expiration date and CVC/security code input do not have this problem.
When I eliminate the spaces in the credit card number, I still have the same problem (the number is randomly garbled during input).
Even when I set the wait time before and after card number input to 5 seconds each, the card number still gets garbled.
How can I input the credit card number in behat/mink without garbling the number?

I don't know anything about behat or mink, but I would suggest you remove the spaces; those all look like they contain the same numbers, just in different orders, so the spaces might be causing issues as the cursor might be moving around a bit.

Summary: You have to input the credit card number one digit at a time because Stripe.js will screw up the spacing if you try to input it all at once.
Here's the relevant code I've been using for the past couple weeks:
// Handle randomized iframe numbers by targeting the div above them.
const STRIPE_CARDNO_IFRAME = 'card-number-element';
const STRIPE_EXP_IFRAME = 'expiration-element';
const STRIPE_CVC_IFRAME = 'security-code-element';
/**
* #Then I enter my credit card number :cc_number
*/
public function iEnterMyCreditCardNumber($cc_number) {
$payment_errors_element = $this->getSession()->getPage()->find('css', 'div#payment-errors');
if ($payment_errors_element->getText()) {
throw new Exception($payment_errors_element->getText());
}
echo "Test credit card number: $cc_number\n";
$this->switchToMyIframe(self::STRIPE_CARDNO_IFRAME);
$this->getSession()->wait(5000);
$credit_card_field = $this->getSession()->getPage()->findField('cardnumber');
$cc_number_nospaces = str_replace(' ', '', "$cc_number");
$creditcard_singledigits = str_split("$cc_number_nospaces", 1);
foreach ($creditcard_singledigits as $creditcard_singledigit) {
$this->getSession()->wait(2000);
$credit_card_field->sendKeys("$creditcard_singledigit");
}
// Take a screenshot for debugging when the card number is entered incorrectly.
$this->saveScreenshot();
$this->getSession()->switchToIFrame(null);
}
/*
* Helper function to find the iframe.
*/
private function switchToMyIframe($selector) {
$iframe_selector = "div#$selector iframe";
$iframe = $this->getSession()->getPage()->find('css', $iframe_selector);
$iframe_name = $iframe->getAttribute('name');
echo "Switching to iframe $iframe_name\n";
$this->getSession()->switchToIFrame("$iframe_name");
}

Related

Error when sending message to Bloomberg via QuickFixJ

I'm trying to sending packet type X to Bloomberg via QuickFixJ. I'm able to connect successfully but when I send the packet, I receive an error message :
8=FIXT.1.1^A9=160^A35=X^A34=4^A49=ARHGBETA^A52=20210915-13:16:04.156^A56=BBGBETA^A1022=****^A22=1^A48=BQ4434677^A268=2^A279=0^A269=0^A270=99.00357818603516^A279=0^A269=1^A270=99.01358032226562^A10=060^A
8=FIXT.1.1^A9=253^A35=j^A49=BBGBETA^A56=ARHGBETA^A34=4^A52=20210915-13:16:04.380^A45=4^A372=X^A380=0^A58=Validation failed for incoming X packet:
In mDIncGrp: In groupMDEntries[0]: NULL component instrument_MarketData
In groupMDEntries[1]: NULL component instrument_MarketData
And yet, I don't see how to define the component instrument_MarketData. I'm using the following code to generate the groups:
/**
* Méthode de création d'un nouveau prix pour le publier sur Bloomberg
* #param marketPrice
* */
public MarketDataIncrementalRefresh createMarketDataIncrementalRefresh(MarketPrice marketPrice) {
quickfix.fix50sp2.MarketDataIncrementalRefresh message = new MarketDataIncrementalRefresh();
quickfix.fix50sp2.MarketDataIncrementalRefresh.NoMDEntries group = new MarketDataIncrementalRefresh.NoMDEntries();
message.getHeader().setString(1022, "****");
quickfix.fix50sp2.component.MDIncGrp mdIncGrp = new MDIncGrp();
mdIncGrp.setString(48, marketPrice.getCUSIP());
mdIncGrp.setString(22, "1");
Instrument instrument =new Instrument();
/**
* Ajout prix Bid au message
* */
instrument.setString(279, "0");
instrument.setString(269, "0");
instrument.setString(270, marketPrice.getBid_kech().toString());
group.set(instrument);
mdIncGrp.addGroup(group);
/**
* Ajout prix Ask au message
* */
instrument.setString(279, "0");
instrument.setString(269, "1");
instrument.setString(270, marketPrice.getAsk_kech().toString());
group.set(instrument);
mdIncGrp.addGroup(group);
message.set(mdIncGrp);
return message;
}
What am I doing wrong? Should I define a custom dictionary to be able to send the message or can I do it with the default dictionary?
Many thanks in advance !
You do not need a custom dictionary to send custom messages. Dictionary validation is only done for received messages, so you might need to alter your dictionary to successfully receive the responses sent by your counterparty.
As to your problem: the error sounds as if something is missing in your group regarding the instrument. Looking at your code I think you mix up the group stuff a bit. I posted this link for an earlier question of you: https://www.quickfixj.org/usermanual/2.3.0/usage/repeating_groups.html
I think the important part is that you should add the group to the message like so:
quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries group =
new quickfix.fix42.MarketDataSnapshotFullRefresh.NoMDEntries();
group.set(new MDEntryType('0'));
group.set(new MDEntryPx(12.32));
group.set(new MDEntrySize(100));
group.set(new OrderID("ORDERID"));
message.addGroup(group); // important part
In your code you are adding a group to a group (mdIncGrp.addGroup(group)) and do a message.set(mdIncGrp) where you really should use addGroup(). Because of this the 48/SecurityID field does not end up in the MDIncGrp but the root message.
8=FIXT.1.1^....removed...^A22=1^A48=BQ4434677^A268=2^A279=0^A269=0^A270=99.00357818603516^A279=0^A269=1^A270=99.01358032226562^A10=060^A
^^^ 48 is here where it should really
be in each of these groups starting with delimiter tag 279

Property Photo Files with PHRETS v2

My php code, below, attemps to download all the photos for a property listing. It successfully queries the RETS server, and creates a file for each photo, but the file does not seem to be a functional image. (MATRIX requires files to be downloaded, instead of URLs.)
The list of photos below suggests that it successfully queries one listing id (47030752) for all photos that exist, (20 photos in this case). In a web browser, the files appear only as a small white square on a black background: e.g. (https://photos.atlantarealestate-homes.com/photos/PHOTO-47030752-9.jpg). The file size (4) also seems to be very low, as compared to that of a real photo.
du -s PHOTO*
4 PHOTO-47030752-10.jpg
4 PHOTO-47030752-11.jpg
4 PHOTO-47030752-12.jpg
4 PHOTO-47030752-13.jpg
4 PHOTO-47030752-14.jpg
4 PHOTO-47030752-15.jpg
4 PHOTO-47030752-16.jpg
4 PHOTO-47030752-17.jpg
4 PHOTO-47030752-18.jpg
4 PHOTO-47030752-19.jpg
4 PHOTO-47030752-1.jpg
4 PHOTO-47030752-20.jpg
4 PHOTO-47030752-2.jpg
4 PHOTO-47030752-3.jpg
4 PHOTO-47030752-4.jpg
4 PHOTO-47030752-5.jpg
4 PHOTO-47030752-6.jpg
4 PHOTO-47030752-7.jpg
4 PHOTO-47030752-8.jpg
4 PHOTO-47030752-9.jpg
script I'm using:
#!/usr/bin/php
<?php
date_default_timezone_set('this/area');
require_once("composer/vendor/autoload.php");
$config = new \PHRETS\Configuration;
$config->setLoginUrl('https://myurl/login.ashx')
->setUsername('myser')
->setPassword('mypass')
->setRetsVersion('1.7.2');
$rets = new \PHRETS\Session($config);
$connect = $rets->Login();
$system = $rets->GetSystemMetadata();
$resources = $system->getResources();
$classes = $resources->first()->getClasses();
$classes = $rets->GetClassesMetadata('Property');
$host="localhost";
$user="db_user";
$password="db_pass";
$dbname="db_name";
$tablename="db_table";
$link=mysqli_connect ($host, $user, $password, $dbname);
$query="select mlsno, matrix_unique_id, photomodificationtimestamp from fmls_homes left join fmls_images on (matrix_unique_id=mls_no and photonum='1') where photomodificationtimestamp <> last_update or last_update is null limit 1";
print ("$query\n");
$result= mysqli_query ($link, $query);
$num_rows = mysqli_num_rows($result);
print "Fetching Images for $num_rows Homes\n";
while ($Row= mysqli_fetch_array ($result)) {
$matrix_unique_id="$Row[matrix_unique_id]";
$objects = $rets->GetObject('Property', 'LargePhoto', $matrix_unique_id);
foreach ($objects as $object) {
// does this represent some kind of error
$object->isError();
$object->getError(); // returns a \PHRETS\Models\RETSError
// get the record ID associated with this object
$object->getContentId();
// get the sequence number of this object relative to the others with the same ContentId
$object->getObjectId();
// get the object's Content-Type value
$object->getContentType();
// get the description of the object
$object->getContentDescription();
// get the sub-description of the object
$object->getContentSubDescription();
// get the object's binary data
$object->getContent();
// get the size of the object's data
$object->getSize();
// does this object represent the primary object in the set
$object->isPreferred();
// when requesting URLs, access the URL given back
$object->getLocation();
// use the given URL and make it look like the RETS server gave the object directly
$object->setContent(file_get_contents($object->getLocation()));
$listing = $object->getContentId();
$number = $object->getObjectId();
$url = $object->getLocation();
//$photo = $object->getContent();
$size = $object->getSize();
$desc = $object->getContentDescription();
if ($number >= '1') {
file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");
print "$listing - $number - $size $desc\n";
} //end if
} //end foreach
} //end while
mysqli_close ($link);
fclose($f);
php?>
Are there any suggested changes to capture photos into the created files? This command creates the photo files:
file_put_contents("/bigdirs/fmls_pics/PHOTO-{$listing}-{$number}.jpg", "$object->getContent();");
There may be some parts of this script that wouldn't work in live production, but are sufficient for testing. This script seems to successfully query for the information needed from the RETS server. The problem is just simply that the actual files created do not seem to be functional photos.
Thanks in Advance! :)
Your code sample is a mix of the official documentation and a usable implementation. The problem is with this line:
$object->setContent(file_get_contents($object->getLocation()));
You should completely take that out. That's actually overriding the image you downloaded with nothing before you get a chance to save the contents to a file. With that removed, it should work as expected.

Prestashop 1.7.4.2 - free shipping based on final total price

I need shipping calculation after discount applied
Ex.
Total cart : 65$
Free shipping start : 65$
Discount : 5%
After discount it become under 65$ and still get free shipping
I need it to calculate discount before shipping
First set your ranges by carrier (0-65: X EUR, above 65: 0 EUR)
Do an override of the class Cart.php
Rewrite function getPackageShippingCost
After line
// Order total in default currency without fees
$order_total = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
Add this
//Recalcul total pour panier et livraison gratuite
$listeDiscounts = $this->getCartRules();
$total_discounts = 0;
if (is_array($listeDiscounts)) {
if (isset($listeDiscounts[0]['value_real']))
$total_discounts = $listeDiscounts[0]['value_real'];
}
$price_to_apply_shipment = floatval($order_total) - floatval($total_discounts);
Replace
//$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int)$id_zone, (int)$this->id_currency);
by
$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $price_to_apply_shipment, (int)$id_zone, (int)$this->id_currency);
And
//$shipping_cost += $carrier->getDeliveryPriceByPrice($the_total_price, $id_zone, (int)$this->id_currency);
By
$shipping_cost += $carrier->getDeliveryPriceByPrice($price_to_apply_shipment, $id_zone, (int)$this->id_currency);
Clear the cache and run
The bottom two changes can be replaced by:
$total_package_without_shipping_tax_inc
= $order_total
= $orderTotalwithDiscounts
= $price_to_apply_shipment;
These variables are only used in these two places along the way

I want to generate 3000 above pdf files from prestashop back end

I am using tcpdf pdf generator for generating Eticket, as same as the prestahsop generates the pdf files for invoices , I am trying to generate the pdf files of tickets( I am selling tickets online) ,3000 tickets daily I need to print from the back end how to do this 3000 tickets printing ??I mean how to generate 3000 tickets of pdf in one click ?
Also I need to validate the printing whether 3000 pdf for the corresponding ticket was generated or not how to do this validation(count validation).
public function generatePDF($object, $template)
{
switch($template) {
case PDF::TEMPLATE_ETICKET:
$format = 'JIS_B5'; // Replace with your desired size for Back office Eticket
break;
default:
$format = 'A4'; // Replace with normal size
}
$pdf = new PDF($object, $template, Context::getContext()->smarty,'P', $format);
$pdf = $pdf->render(false);
return true;
}

Paypal ipn/cart variables

Wondered if anyone could give me any pointers?
The website I'm currently building sells 'event' tickets....holidays.
What I'm trying to do is decrease the number of tickets in a database field by the number purchased BUT can't find a paypal cart variable which will pull the information back. The custom variable it seems can only be used once and the item_name and item_number variables are already being used, the (item_number) to identify the 'event_id' field in the database and the (item_name) to obviously identify the event name.
I can pass the correct number of tickets to be updated over to Paypal by decreasing the amount and echoing that out in a hidden form field prior to sumbitting to Paypal BUT I can't get the results back. I'm looking for a Paypal form 'name' field that can be adapted to my needs, if one exists
Below is the database loop: The 'custom' variable doesn't work as it can't be custom1, custom2 etc.
mysql_connect('xxxxxxxx', 'xxxxxx', 'xxxxxxxx') or exit(0);
mysql_select_db('xxxxxx') or exit(0);
$num_cart_items = $_POST['num_cart_items'];
$i=1;
while (isset($_POST['item_number'.$i]))//read the item details
{
$item_ID[$i]=$_POST['item_number'.$i];
$custom[$i]=$_POST['custom'.$i];
$i++;
}
$item_count = $i-1;
for ($j=1;$j<=$item_count;$j++)
{
$struery = "UPDATE events SET event_tickets = '".$custom[$j]."' WHERE event_id = '".$item_ID[$j]."'";
$result = mysql_query($struery) or die("Cart - paypal_cart_info, Query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$i++;
}// end database loop
Thanks for any info.
Os
You can put custom variable as JSON encoded string. Then decode it.
$i=1;
$custom = json_decode($_POST['custom], TRUE);
while (isset($_POST['item_number'.$i]))//read the item details
{
$item_ID[$i] = $_POST['item_number'.$i];
$custom[$i] = $custom[$i];
$i++;
}
Or you can even base64_encode it on send to paypal and верут decode it back it you want variable not to be readable when you redirect user to paypal.